aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmp Tell <ampleyfly@gmail.com>2025-07-07 15:31:45 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-08-01 14:05:57 +0300
commit37c46a56a1ccd0f7a758cccd0864b6faf6f0bcf3 (patch)
tree6aa5a53febf229bc1635b96737d9813d3761a501
parent4e73d6913adb165b71abf5fe7506b7fe77b1e809 (diff)
downloadmeson-37c46a56a1ccd0f7a758cccd0864b6faf6f0bcf3.zip
meson-37c46a56a1ccd0f7a758cccd0864b6faf6f0bcf3.tar.gz
meson-37c46a56a1ccd0f7a758cccd0864b6faf6f0bcf3.tar.bz2
wrap: Add basic sftp support to wrap.get_data()
This requires any credentials to be supplied in the url, or some other means of authentication (such as an identity file configured for the user) to be used. Supplying a password in the URL is not supported.
-rw-r--r--mesonbuild/wrap/wrap.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index fe2910f..a9d1b7b 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -743,6 +743,23 @@ class Resolver:
resp = open_wrapdburl(urlstring, allow_insecure=self.allow_insecure, have_opt=self.wrap_frontend)
elif WHITELIST_SUBDOMAIN in urlstring:
raise WrapException(f'{urlstring} may be a WrapDB-impersonating URL')
+ elif url.scheme == 'sftp':
+ sftp = shutil.which('sftp')
+ if sftp is None:
+ raise WrapException('Scheme sftp is not available. Install sftp to enable it.')
+ with tempfile.TemporaryDirectory() as workdir, \
+ tempfile.NamedTemporaryFile(mode='wb', dir=self.cachedir, delete=False) as tmpfile:
+ args = []
+ # Older versions of the sftp client cannot handle URLs, hence the splitting of url below
+ if url.port:
+ args += ['-P', f'{url.port}']
+ user = f'{url.username}@' if url.username else ''
+ command = [sftp, '-o', 'KbdInteractiveAuthentication=no', *args, f'{user}{url.hostname}:{url.path[1:]}']
+ subprocess.run(command, cwd=workdir, check=True)
+ downloaded = os.path.join(workdir, os.path.basename(url.path))
+ tmpfile.close()
+ shutil.move(downloaded, tmpfile.name)
+ return self.hash_file(tmpfile.name), tmpfile.name
else:
headers = {
'User-Agent': f'mesonbuild/{coredata.version}',