Decide whether a trail's files are up to date by its content key, kept in the trail's cache entry, instead of modification times, so a changed track put back to an older time is built again into the same directory

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 17:49:37 -07:00
1 parent 9c7cc55cc5
commit 2be6693a94
2 files changed
+46 -28

No files matched your search

+26
View File
@@ -228,5 +228,31 @@ class BuildShortcutsTest(unittest.TestCase):
self.assertEqual(self.key(tid), key_before)
def test_a_rebuild_into_the_same_directory_follows_content_not_modification_times(self):
out, cache = self.dirs("same")
self.build(out, cache, 1)
tid = next(t for t in self.ids if os.path.isfile(os.path.join(self.root, t, "line.geojson")))
line = os.path.join(self.root, tid, "line.geojson")
with open(line, encoding="utf-8") as f:
original = f.read()
stat = os.stat(line)
try:
moved = [[[c[0] + 0.5, *c[1:]] for c in part] for part in geo.parts_from_geojson(json.loads(original))]
with open(line, "w", encoding="utf-8") as f:
json.dump({"type": "Feature", "properties": {},
"geometry": {"type": "MultiLineString", "coordinates": moved}}, f)
long_ago = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, -1))
os.utime(line, (long_ago, long_ago))
os.utime(os.path.join(self.root, tid), (long_ago, long_ago))
self.build(out, cache, 1) # the same directory, the same cache
fresh, empty = self.dirs("same-fresh")
self.build(fresh, empty, 1)
same_tree(self, out, fresh)
finally:
with open(line, "w", encoding="utf-8") as f:
f.write(original)
os.utime(line, ns=(stat.st_atime_ns, stat.st_mtime_ns))
if __name__ == "__main__":
unittest.main()