Fix missing .hex() when inserting SHA256

This commit is contained in:
Jacob Hinkle 2022-10-11 12:49:11 -04:00
parent 8e69ca3390
commit 7a0fea9a80
3 changed files with 24 additions and 31 deletions

View File

@ -37,7 +37,7 @@ deps =
pytest-cov
coverage
commands =
pytest --cov {envsitepackagesdir}/nancy
pytest --cov {envsitepackagesdir}/nancy {posargs}
[testenv:mypy]
deps =

View File

@ -89,9 +89,9 @@ class FSEntryVersion:
"INSERT INTO filedir_version VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
(
self.uuid,
self.filedir.sha256,
self.filedir.sha256.hex(),
datetime.now().timestamp(),
self.filetype,
str(self.filetype),
False,
self.perms,
self.symlink_target,
@ -286,22 +286,16 @@ class FSEntry:
) -> None:
# Find entries with this name and parent
cur.execute(
"SELECT sha256 FROM filedir WHERE store = 1 AND name = ? AND parent = ? LIMIT 1",
(self.filename, None if self.parent is None else self.parent.sha256),
"INSERT OR IGNORE INTO filedir VALUES (?, ?, ?, ?)",
(
self.sha256.hex(),
None if self.store is None else self.store.uuid,
self.filename,
parent_key,
),
)
res = cur.fetchall()
if len(res) == 0:
# create filedir entry and get its id
cur.execute(
"INSERT INTO filedir VALUES (?, ?, ?, ?)",
(
self.sha256,
None if self.store is None else self.store.uuid,
self.filename,
parent_key,
),
)
self.versions[-1].persist(cur=cur, source_task=source_task)
for v in self.versions:
v.persist(cur=cur, source_task=source_task)
# descend into children and record all of them anew as well
for c in self.children:

View File

@ -30,6 +30,7 @@ class Store:
self,
directory: fs.PathStr,
conn: Optional[sqlite3.Connection] = None,
uuid: Optional[str] = None,
):
self.path = Path(directory)
self.db_path = self.path / "nancy.db"
@ -39,7 +40,7 @@ class Store:
else:
self.conn = conn
self.uuid = self.find_store_uuid()
self.uuid = self.find_store_uuid() if uuid is None else uuid
def copy(self: _StoreT, store_path: fs.PathStr) -> _StoreT:
"""Copy this store to a new store path"""
@ -94,21 +95,19 @@ class Store:
conn.commit()
cur.close()
new_store = cls(directory=directory, conn=conn)
new_uuid = str(uuid.uuid4())
new_store = cls(directory=directory, conn=conn, uuid=new_uuid)
# generate a new UUID for this store
with new_store.committing() as cur:
cur.execute(
'INSERT INTO local_metadata VALUES ("store_uuid", ?)',
(new_store.uuid,),
)
with new_store.new_program("INIT", message) as p:
# set the timing to the actual times it took to initialize the db
p.start_time = start_time
# generate a new UUID for this store
assert new_store.uuid is None
new_store.uuid = str(uuid.uuid4())
with new_store.committing() as cur:
cur.execute(
'INSERT INTO local_metadata VALUES ("store_uuid", ?)',
(new_store.uuid,),
)
return new_store
def filedir_root_key(self, cur: Optional[sqlite3.Cursor] = None) -> Optional[str]:
@ -116,7 +115,7 @@ class Store:
if cur is None:
assert self.conn is not None
cur = self.conn.cursor()
cur.execute("SELECT uuid FROM filedir WHERE store=1 AND parent is NULL")
cur.execute("SELECT sha256 FROM filedir WHERE store=1 AND parent is NULL")
row = cur.fetchone()
if row is None:
return None
@ -147,7 +146,7 @@ class Store:
for p in Path(rel).parts: # Path.parts splits a path reliably
# get child with that name
cur.execute(
"SELECT uuid, filetype FROM filedir WHERE filename=? AND parent=? LIMIT 1",
"SELECT sha256, filetype FROM filedir WHERE filename=? AND parent=? LIMIT 1",
(p, fd_key),
)
row = cur.fetchone()