diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2024-06-02 05:05:36 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2024-06-02 13:54:46 +0200 |
commit | adb5e2a6e766eecedd2aead41387f50ffc7b26ed (patch) | |
tree | 5796599c59c2e8bbeb6ca41a200dc92107b618ba | |
parent | d25c8b8b60fbfabf7544a3a5a44c105f0bc5b4da (diff) |
webmap-download: Ensure we always call linkat() not link().
This costs an extra file descriptor when --cachedir is unsed, but
os.link(f'/proc/self/fd/{fp.fileno()}', newpath,
dst_dir_fd=None, follow_symlinks=True)
calls link("/proc/self/fd/…", newpath) rather than
linkat(AT_FDCWD, "/proc/self/fd/…", AT_FDCWD, newpath, AT_SYMLINK_FOLLOW)
and the former fails with EXDEV (Invalid cross-device link).
-rwxr-xr-x | webmap-download | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/webmap-download b/webmap-download index be48bbb..03c05af 100755 --- a/webmap-download +++ b/webmap-download @@ -136,8 +136,8 @@ if __name__ == '__main__': logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) parser = argparse.ArgumentParser(description='Download or update GIS layers.') - parser.add_argument('--cachedir', default=None, - help='destination directory for downloaded files (default: .)') + parser.add_argument('--cachedir', default=os.curdir, + help=f'destination directory for downloaded files (default: {os.curdir})') parser.add_argument('--lockdir', default=None, help='optional directory for lock files') parser.add_argument('--debug', action='store_true', help=argparse.SUPPRESS) @@ -171,8 +171,8 @@ if __name__ == '__main__': # intentionally leave the dirfd open until the program terminates opendir_args = O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY - destdir_fd = None if args.cachedir is None else os.open(args.cachedir, opendir_args) - lockdir_fd = None if args.lockdir is None else os.open(args.lockdir, opendir_args) + destdir_fd = os.open(args.cachedir, opendir_args) + lockdir_fd = None if args.lockdir is None else os.open(args.lockdir, opendir_args) sessionRequests = requests.Session() |