|
21 | 21 | raises = None |
22 | 22 |
|
23 | 23 | from ..fuse_impl import llfuse, has_any_fuse, has_llfuse, has_pyfuse3, has_mfusepy, ENOATTR # NOQA |
24 | | -from .. import platform |
| 24 | +from borg import platform as borg_platform |
25 | 25 | from ..platformflags import is_win32, is_darwin |
26 | 26 |
|
27 | 27 | # Does this version of llfuse support ns precision? |
|
32 | 32 | has_lchflags = hasattr(os, "lchflags") or sys.platform.startswith("linux") |
33 | 33 | try: |
34 | 34 | with tempfile.NamedTemporaryFile() as file: |
35 | | - platform.set_flags(file.name, stat.UF_NODUMP) |
| 35 | + borg_platform.set_flags(file.name, stat.UF_NODUMP) |
36 | 36 | except OSError: |
37 | 37 | has_lchflags = False |
38 | 38 |
|
@@ -185,42 +185,51 @@ def are_fifos_supported(): |
185 | 185 | def is_utime_fully_supported(): |
186 | 186 | with unopened_tempfile() as filepath: |
187 | 187 | # Some filesystems (such as SSHFS) don't support utime on symlinks |
188 | | - if are_symlinks_supported(): |
| 188 | + if are_symlinks_supported() and not is_win32: |
189 | 189 | os.symlink("something", filepath) |
| 190 | + try: |
| 191 | + os.utime(filepath, (1000, 2000), follow_symlinks=False) |
| 192 | + new_stats = os.stat(filepath, follow_symlinks=False) |
| 193 | + if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: |
| 194 | + return True |
| 195 | + except OSError: |
| 196 | + pass |
| 197 | + except NotImplementedError: |
| 198 | + pass |
190 | 199 | else: |
191 | 200 | open(filepath, "w").close() |
192 | | - try: |
193 | | - os.utime(filepath, (1000, 2000), follow_symlinks=False) |
194 | | - new_stats = os.stat(filepath, follow_symlinks=False) |
195 | | - if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: |
196 | | - return True |
197 | | - except OSError: |
198 | | - pass |
199 | | - except NotImplementedError: |
200 | | - pass |
201 | | - return False |
| 201 | + try: |
| 202 | + os.utime(filepath, (1000, 2000)) |
| 203 | + new_stats = os.stat(filepath) |
| 204 | + if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000: |
| 205 | + return True |
| 206 | + except OSError: |
| 207 | + pass |
| 208 | + return False |
202 | 209 |
|
203 | 210 |
|
204 | 211 | @functools.lru_cache |
205 | 212 | def is_birthtime_fully_supported(): |
206 | | - if not hasattr(os.stat_result, "st_birthtime"): |
207 | | - return False |
208 | 213 | with unopened_tempfile() as filepath: |
209 | 214 | # Some filesystems (such as SSHFS) don't support utime on symlinks |
210 | | - if are_symlinks_supported(): |
| 215 | + if are_symlinks_supported() and not is_win32: |
211 | 216 | os.symlink("something", filepath) |
212 | 217 | else: |
213 | 218 | open(filepath, "w").close() |
214 | 219 | try: |
215 | | - birthtime, mtime, atime = 946598400, 946684800, 946771200 |
216 | | - os.utime(filepath, (atime, birthtime), follow_symlinks=False) |
217 | | - os.utime(filepath, (atime, mtime), follow_symlinks=False) |
218 | | - new_stats = os.stat(filepath, follow_symlinks=False) |
219 | | - if new_stats.st_birthtime == birthtime and new_stats.st_mtime == mtime and new_stats.st_atime == atime: |
| 220 | + birthtime_ns, mtime_ns, atime_ns = 946598400 * 10**9, 946684800 * 10**9, 946771200 * 10**9 |
| 221 | + borg_platform.set_birthtime(filepath, birthtime_ns) |
| 222 | + os.utime(filepath, ns=(atime_ns, mtime_ns)) |
| 223 | + new_stats = os.stat(filepath) |
| 224 | + bt = borg_platform.get_birthtime_ns(new_stats, filepath) |
| 225 | + if ( |
| 226 | + bt is not None |
| 227 | + and same_ts_ns(bt, birthtime_ns) |
| 228 | + and same_ts_ns(new_stats.st_mtime_ns, mtime_ns) |
| 229 | + and same_ts_ns(new_stats.st_atime_ns, atime_ns) |
| 230 | + ): |
220 | 231 | return True |
221 | | - except OSError: |
222 | | - pass |
223 | | - except NotImplementedError: |
| 232 | + except (OSError, NotImplementedError, AttributeError): |
224 | 233 | pass |
225 | 234 | return False |
226 | 235 |
|
|
0 commit comments