Fix Windows snapshot timestamps and validate Turbo master caches
This commit is contained in:
1 parent
229f6464f0
commit
060acc2945
5 files changed
+139
-27
No files matched your search
@@ -131,6 +131,24 @@ def test_source_change_and_failed_commit(tmp_path, monkeypatch):
|
||||
assert not (repo/'.writer-lock').exists()
|
||||
|
||||
|
||||
def test_path_and_handle_ctime_can_differ(tmp_path, monkeypatch):
|
||||
# CPython on Windows can report creation time from lstat, but change
|
||||
# time from fstat. Reproduce the discrepancy independently of the OS.
|
||||
original = os.fstat
|
||||
class HandleStat:
|
||||
def __init__(self, fd):
|
||||
self.value = original(fd)
|
||||
self.st_ctime_ns = self.value.st_ctime_ns + 10**9
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.value, name)
|
||||
monkeypatch.setattr(s.os, 'fstat', HandleStat)
|
||||
source, repo = tmp_path/'source', tmp_path/'repo'
|
||||
source.mkdir(); (source/'data').write_bytes(b'updated file')
|
||||
result = s.create(source, repo)
|
||||
s.restore(repo, result['snapshot'], tmp_path/'restored')
|
||||
assert tree(tmp_path/'restored') == tree(source)
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == 'nt', reason='requires POSIX symlink/FIFO privileges')
|
||||
def test_symlinks_special_files_and_collisions(tmp_path):
|
||||
src, repo = tmp_path/'src', tmp_path/'repo'
|
||||
|
||||
+11
-3
@@ -297,13 +297,14 @@ def create(source, repository, *, label="", max_total_size=1 << 40):
|
||||
keys.add(key)
|
||||
if len(keys) > MAX_ENTRIES:
|
||||
raise ValueError("snapshot entry limit exceeded")
|
||||
mode = path.lstat().st_mode
|
||||
path_before = path.lstat()
|
||||
mode = path_before.st_mode
|
||||
if stat.S_ISDIR(mode):
|
||||
entry = dict(path=relative)
|
||||
entries.append(entry)
|
||||
visit(path, entry)
|
||||
elif stat.S_ISREG(mode):
|
||||
entry = dict(path=relative, **_metadata(path, "file"), chunks=[])
|
||||
entry = dict(path=relative, **_metadata(path, "file", path_before), chunks=[])
|
||||
sha, size = hashlib.sha256(), 0
|
||||
with _regular(path) as stream:
|
||||
before = os.fstat(stream.fileno())
|
||||
@@ -323,7 +324,14 @@ def create(source, repository, *, label="", max_total_size=1 << 40):
|
||||
after = os.fstat(stream.fileno())
|
||||
current = path.lstat()
|
||||
signature = lambda s: (s.st_dev, s.st_ino, s.st_size, s.st_mtime_ns, s.st_ctime_ns)
|
||||
if signature(before) != signature(after) or signature(before) != signature(current) or size != before.st_size:
|
||||
# Windows fstat and lstat can give ctime different
|
||||
# meanings (change time versus creation time). Compare
|
||||
# timestamps only within the same API, and identities
|
||||
# across APIs. Keep both change checks on every OS.
|
||||
if (signature(before) != signature(after) or
|
||||
signature(path_before) != signature(current) or
|
||||
(before.st_dev, before.st_ino) != (path_before.st_dev, path_before.st_ino) or
|
||||
size != before.st_size):
|
||||
raise ValueError(f"source changed during snapshot: {relative}")
|
||||
entry.update(size=size, sha256=sha.hexdigest(), mtime_ns=before.st_mtime_ns,
|
||||
mode=stat.S_IMODE(before.st_mode) & 0o777)
|
||||
|
||||
Reference in new issue
Block a user