From adb5e2a6e766eecedd2aead41387f50ffc7b26ed Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 2 Jun 2024 05:05:36 +0200 Subject: webmap-download: Ensure we always call linkat() not link(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- webmap-download | 8 ++++---- 1 file 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() -- cgit v1.2.3