windows: implement st_birthtime restoration, fixes #8730#9341
windows: implement st_birthtime restoration, fixes #8730#9341trxvorr wants to merge 1 commit intoborgbackup:masterfrom
Conversation
d6dbc75 to
2f50ad0
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9341 +/- ##
==========================================
- Coverage 76.03% 76.01% -0.03%
==========================================
Files 85 85
Lines 14744 14752 +8
Branches 2194 2195 +1
==========================================
+ Hits 11211 11213 +2
- Misses 2856 2862 +6
Partials 677 677 ☔ View full report in Codecov by Sentry. |
9b57619 to
a1face0
Compare
2037eea to
55000f7
Compare
55000f7 to
91be6ae
Compare
| raise NotImplementedError | ||
|
|
||
|
|
||
| def set_birthtime(path, birthtime_ns): |
There was a problem hiding this comment.
is there also a way to do this with an open file descriptor?
There was a problem hiding this comment.
a lot of borg file functions take a file descriptor and a path. if the (open) file descriptor is provided, the function uses that and if not, it falls back to using the path.
| if sys.platform == "win32": | ||
| platform.set_birthtime("input/file1", birthtime_ns) |
There was a problem hiding this comment.
is_win32
also: don't kill it for other platforms.
| create_test_files(archiver.input_path) | ||
| birthtime, mtime, atime = 946598400, 946684800, 946771200 | ||
| os.utime("input/file1", (atime, birthtime)) | ||
| set_birthtime("input/file1", birthtime * 1_000_000_000) # noqa: F821 |
There was a problem hiding this comment.
don't kill it for other platforms.
| # allow for small differences (e.g. 10ms) | ||
| assert abs(sto.st_birthtime * 1e9 - birthtime * 1e9) < 10_000_000 |
There was a problem hiding this comment.
if we generally have to expect up to 10ms variance on windows, this could be moved into same_ts_ns.
| if not os.path.exists("output"): | ||
| os.makedirs("output") |
There was a problem hiding this comment.
don't we always have the output dir?
also: check makedirs parameters.
| @@ -0,0 +1,52 @@ | |||
| import os | |||
There was a problem hiding this comment.
in the end, this should be in the tests of the extract command.
|
|
||
| from ..fuse_impl import llfuse, has_any_fuse, has_llfuse, has_pyfuse3, has_mfusepy, ENOATTR # NOQA | ||
| from .. import platform | ||
| from borg import platform as borg_platform |
There was a problem hiding this comment.
don't do absolute imports.
| new_stats = os.stat(filepath, follow_symlinks=False) | ||
| if new_stats.st_birthtime == birthtime and new_stats.st_mtime == mtime and new_stats.st_atime == atime: | ||
| birthtime_ns, mtime_ns, atime_ns = 946598400 * 10**9, 946684800 * 10**9, 946771200 * 10**9 | ||
| borg_platform.set_birthtime(filepath, birthtime_ns) |
There was a problem hiding this comment.
don't kill it for other platforms.
This PR implements the restoration of file creation time (
st_birthtime) on Windows, addressing Issue #8730.Changes
ctypesandSetFileTimeto precisely set creation time on NTFS.Archive.restore_attrsto call set_birthtime on Windows when birthtime metadata is present.win32_birthtime_test.py) and E2E (win32_birthtime_e2e_test.py) tests verifying birthtime preservation.st_birthtime!=st_mtimesemantics).Verification