FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; exec rsync -avP \\\"\\\${x%%/*}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
RESUMECOMMAND_SSH=${FETCHCOMMAND_SSH}
+FETCHCOMMAND_SFTP="bash -c \"x=\\\${2#sftp://} ; exec sftp \\\"\\\${x%%/*}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" sftp \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
+
# Default user options
FEATURES="assume-digests binpkg-logs distlocks fixpackages
fixlafiles news parallel-fetch protect-owned
import stat
import subprocess
import sys
+import tempfile
import textwrap
from itertools import chain
try:
rmt_idx = self._new_pkgindex()
parsed_url = urlparse(base_url)
proc = None
+ tmp_filename = None
try:
# urlparse.urljoin() only works correctly with recognized
# protocols and requires the base url to have a trailing
try:
f = urllib_request_urlopen(base_url.rstrip("/") + "/Packages")
except IOError:
- if parsed_url.scheme != 'ssh':
- raise
path = parsed_url.path.rstrip("/") + "/Packages"
- proc = subprocess.Popen(['ssh', parsed_url.netloc, '--',
- 'cat', path], stdout=subprocess.PIPE)
- f = proc.stdout
+ if parsed_url.scheme == 'sftp':
+ # The sftp command complains about 'Illegal seek' if
+ # we try to make it write to /dev/stdout, so use a
+ # temp file instead.
+ fd, tmp_filename = tempfile.mkstemp()
+ os.close(fd)
+ proc = subprocess.Popen(['sftp',
+ parsed_url.netloc + ":" + path, tmp_filename])
+ if proc.wait() != os.EX_OK:
+ raise
+ f = open(tmp_filename, 'rb')
+ elif parsed_url.scheme == 'ssh':
+ proc = subprocess.Popen(['ssh', parsed_url.netloc, '--',
+ 'cat', path], stdout=subprocess.PIPE)
+ f = proc.stdout
+ else:
+ raise
f_dec = codecs.iterdecode(f,
_encodings['repo.content'], errors='replace')
proc.kill()
proc.wait()
proc = None
+ if tmp_filename is not None:
+ try:
+ os.unlink(tmp_filename)
+ except OSError:
+ pass
if pkgindex is rmt_idx:
pkgindex.modified = False # don't update the header
try:
_cases = {
'FETCHCOMMAND' : '/usr/bin/wget -t 5 -T 60 --passive-ftp -O "${DISTDIR}/${FILE}" "${URI}"',
'FETCHCOMMAND_RSYNC' : 'rsync -avP "${URI}" "${DISTDIR}/${FILE}"',
+ 'FETCHCOMMAND_SFTP' : 'bash -c "x=\\${2#sftp://} ; exec sftp \\"\\${x%%/*}:/\\${x#*/}\\" \\"\\$1\\"" sftp "${DISTDIR}/${FILE}" "${URI}"',
'FETCHCOMMAND_SSH' : 'bash -c "x=\\${2#ssh://} ; exec rsync -avP \\"\\${x%%/*}:/\\${x#*/}\\" \\"\\$1\\"" rsync "${DISTDIR}/${FILE}" "${URI}"',
'PORTAGE_ELOG_MAILSUBJECT' : '[portage] ebuild log for ${PACKAGE} on ${HOST}'
}