Repository navigation
ltfs_ordered_copy: preserve directory attributes (#392) - #658
Open
MitchelTighe wants to merge 2 commits into
Open
MitchelTighe wants to merge 2 commits into
MitchelTighe wants to merge 2 commits into
Conversation
…m#392) Directories were created with os.mkdir() and nothing else, so even with -p or -a every copied directory got the current time and the umask default mode, and its extended attributes were dropped. Remember each source/destination directory pair while walking the tree, and once all files have been copied apply the attributes with shutil.copystat() (plus the xattrs when -a is given). This has to happen after the copy, because writing a file updates the mtime of the directory that contains it, and deepest first, because updating a child directory updates its parent. Without -p/-a the behaviour is unchanged. Fixes LinearTapeFileSystem#392
MitchelTighe
marked this pull request as draft
October 16, 2026 00:37
- Do not touch the attributes of DEST itself when the source is given as "dir/" or ".", which copy the contents of the directory into DEST. - Order the directories by destination depth, not by source path length: with several sources the two can disagree, and a parent made read-only first blocks the update of its children. - Copy extended attributes before copystat() makes a read-only directory read-only, and treat a failing xattr.list() as a warning like the other attribute failures instead of aborting the copy.
MitchelTighe
marked this pull request as ready for review
October 16, 2026 00:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #392
ltfs_ordered_copycreates destination directories withos.mkdir()only, so even with-por-aevery copied directory gets the current time and the umask default mode, and its extended attributes are dropped.Change
shutil.copystat(), plus the xattrs when-ais given.-p/-athe behaviour is unchanged. A failure to copy one directory's attributes is logged as a warning and doesn't abort the copy.Testing
I ran the tool against a small local harness, an on-disk source tree plus an xattr shim standing in for an LTFS volume, so no real tape was involved. These cases were checked:
-r -pon nested directories with distinct modes and mtimes: before the patch they got umask/now; after it they match the source.-p, directories keep the default mode, as before.Written with help from an AI assistant (Claude).
Update (second commit): after a closer review, three things were tightened:
dir/or.copies its contents into DEST. In that case DEST's own attributes are now left alone; the first version overwrote them with the source directory's.copystat(), and an error fromxattr.list()is logged as a warning instead of aborting the run.Out of scope: intermediate directories created by
--keep-tree(viaos.makedirs()) still get default attributes. That's the same as currentmain, and it would be better handled separately.