From 2dec011ca93008b9fb8c3e2fb82bb8f485833bd9 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Tue, 2 Nov 2021 22:35:23 +0300 Subject: [PATCH] Fix setting symlink attributes in linux --- spqr/curateipsum/fs.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spqr/curateipsum/fs.py b/spqr/curateipsum/fs.py index 49a6444..bcef17a 100644 --- a/spqr/curateipsum/fs.py +++ b/spqr/curateipsum/fs.py @@ -112,12 +112,18 @@ def copy_direntry(entry: os.DirEntry, dst_path): copy_file(entry.path, dst_path) src_stat = entry.stat(follow_symlinks=False) - if not entry.is_symlink() or os.chown in os.supports_follow_symlinks: - os.chown(dst_path, src_stat.st_uid, src_stat.st_gid, follow_symlinks=False) - if not entry.is_symlink() or os.chmod in os.supports_follow_symlinks: - os.chmod(dst_path, src_stat.st_mode, follow_symlinks=False) - if not entry.is_symlink() or os.utime in os.supports_follow_symlinks: - os.utime(dst_path, (src_stat.st_atime, src_stat.st_mtime), follow_symlinks=False) + if entry.is_symlink(): + # change symlink attributes only if supported by OS + if os.chown in os.supports_follow_symlinks: + os.chown(dst_path, src_stat.st_uid, src_stat.st_gid, follow_symlinks=False) + if os.chmod in os.supports_follow_symlinks: + os.chmod(dst_path, src_stat.st_mode, follow_symlinks=False) + if os.utime in os.supports_follow_symlinks: + os.utime(dst_path, (src_stat.st_atime, src_stat.st_mtime), follow_symlinks=False) + else: + os.chown(dst_path, src_stat.st_uid, src_stat.st_gid) + os.chmod(dst_path, src_stat.st_mode) + os.utime(dst_path, (src_stat.st_atime, src_stat.st_mtime)) def update_direntry(src_entry: os.DirEntry, dst_entry: os.DirEntry):