Rename FUID field to key everywhere.

This commit is contained in:
Leo Vasanko
2023-11-05 15:54:55 +00:00
parent 9d3d27faf3
commit 14f7253ece
4 changed files with 24 additions and 20 deletions

View File

@@ -110,13 +110,13 @@ class ErrorMsg(msgspec.Struct):
class FileEntry(msgspec.Struct):
id: str
key: str
size: int
mtime: int
class DirEntry(msgspec.Struct):
id: str
key: str
size: int
mtime: int
dir: DirList
@@ -146,7 +146,7 @@ class UpdateEntry(msgspec.Struct, omit_defaults=True):
name: str = ""
deleted: bool = False
id: str | None = None
key: str | None = None
size: int | None = None
mtime: int | None = None
dir: DirList | None = None

View File

@@ -90,7 +90,9 @@ def format_tree():
return msgspec.json.encode(
{
"update": [
UpdateEntry(id=root.id, size=root.size, mtime=root.mtime, dir=root.dir),
UpdateEntry(
key=root.key, size=root.size, mtime=root.mtime, dir=root.dir
),
],
},
).decode()
@@ -99,10 +101,11 @@ def format_tree():
def walk(path: Path) -> DirEntry | FileEntry | None:
try:
s = path.stat()
id_ = fuid(s)
key = fuid(s)
assert key, repr(key)
mtime = int(s.st_mtime)
if path.is_file():
return FileEntry(id_, s.st_size, mtime)
return FileEntry(key, s.st_size, mtime)
tree = {
p.name: v
@@ -115,7 +118,7 @@ def walk(path: Path) -> DirEntry | FileEntry | None:
mtime = max(mtime, *(v.mtime for v in tree.values()))
else:
size = 0
return DirEntry(id_, size, mtime, tree)
return DirEntry(key, size, mtime, tree)
except FileNotFoundError:
return None
except OSError as e: