-
-
Notifications
You must be signed in to change notification settings - Fork 827
windows: implement st_birthtime restoration, fixes #8730 #9341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trxvorr
wants to merge
1
commit into
borgbackup:master
Choose a base branch
from
trxvorr:fix-8730-win-birthtime
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+224
−59
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| raises = None | ||
|
|
||
| from ..fuse_impl import llfuse, has_any_fuse, has_llfuse, has_pyfuse3, has_mfusepy, ENOATTR # NOQA | ||
| from .. import platform | ||
| from .. import platform as borg_platform | ||
trxvorr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from ..platformflags import is_win32, is_darwin | ||
|
|
||
| # Does this version of llfuse support ns precision? | ||
|
|
@@ -32,7 +32,7 @@ | |
| has_lchflags = hasattr(os, "lchflags") or sys.platform.startswith("linux") | ||
| try: | ||
| with tempfile.NamedTemporaryFile() as file: | ||
| platform.set_flags(file.name, stat.UF_NODUMP) | ||
| borg_platform.set_flags(file.name, stat.UF_NODUMP) | ||
| except OSError: | ||
| has_lchflags = False | ||
|
|
||
|
|
@@ -52,6 +52,9 @@ def same_ts_ns(ts_ns1, ts_ns2): | |
| """Compare two timestamps (both in nanoseconds) to determine whether they are (roughly) equal.""" | ||
| diff_ts = int(abs(ts_ns1 - ts_ns2)) | ||
| diff_max = 10 ** (-st_mtime_ns_round) | ||
| # On Windows, we generally have to expect up to 10ms variance. | ||
| if is_win32: | ||
| diff_max = max(diff_max, 10 * 1000 * 1000) | ||
|
Comment on lines
54
to
+57
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like that st_mtime_ns_round is some constant. check where it is defined/used and if it makes sense maybe just define the constant differently on win32. |
||
| return diff_ts <= diff_max | ||
|
|
||
|
|
||
|
|
@@ -187,40 +190,49 @@ def is_utime_fully_supported(): | |
| # Some filesystems (such as SSHFS) don't support utime on symlinks | ||
| if are_symlinks_supported(): | ||
| os.symlink("something", filepath) | ||
| try: | ||
| os.utime(filepath, (1000, 2000), follow_symlinks=False) | ||
| new_stats = os.stat(filepath, follow_symlinks=False) | ||
| if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: | ||
| return True | ||
| except OSError: | ||
| pass | ||
| except NotImplementedError: | ||
| pass | ||
| else: | ||
| open(filepath, "w").close() | ||
| try: | ||
| os.utime(filepath, (1000, 2000), follow_symlinks=False) | ||
| new_stats = os.stat(filepath, follow_symlinks=False) | ||
| if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: | ||
| return True | ||
| except OSError: | ||
| pass | ||
| except NotImplementedError: | ||
| pass | ||
| return False | ||
| try: | ||
| os.utime(filepath, (1000, 2000)) | ||
| new_stats = os.stat(filepath) | ||
| if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: | ||
| return True | ||
| except OSError: | ||
| pass | ||
| return False | ||
|
|
||
|
|
||
| @functools.lru_cache | ||
| def is_birthtime_fully_supported(): | ||
| if not hasattr(os.stat_result, "st_birthtime"): | ||
| return False | ||
| with unopened_tempfile() as filepath: | ||
| # Some filesystems (such as SSHFS) don't support utime on symlinks | ||
| if are_symlinks_supported(): | ||
| os.symlink("something", filepath) | ||
| else: | ||
| open(filepath, "w").close() | ||
| try: | ||
| birthtime, mtime, atime = 946598400, 946684800, 946771200 | ||
| os.utime(filepath, (atime, birthtime), follow_symlinks=False) | ||
| os.utime(filepath, (atime, mtime), follow_symlinks=False) | ||
| 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) | ||
trxvorr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| os.utime(filepath, ns=(atime_ns, mtime_ns)) | ||
| new_stats = os.stat(filepath) | ||
| bt = borg_platform.get_birthtime_ns(new_stats, filepath) | ||
| if ( | ||
| bt is not None | ||
| and same_ts_ns(bt, birthtime_ns) | ||
| and same_ts_ns(new_stats.st_mtime_ns, mtime_ns) | ||
| and same_ts_ns(new_stats.st_atime_ns, atime_ns) | ||
| ): | ||
| return True | ||
| except OSError: | ||
| pass | ||
| except NotImplementedError: | ||
| except (OSError, NotImplementedError, AttributeError): | ||
| pass | ||
| return False | ||
|
|
||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.