From 8d6395ecd16dbed35daf0cb3613ca9a770a9efe4 Mon Sep 17 00:00:00 2001 From: Jacob Hinkle Date: Thu, 22 Sep 2022 10:03:44 -0400 Subject: [PATCH] Rename store_file table to filedir --- src/nancy/fs.py | 6 +++--- src/nancy/schema/version0.sql | 18 +++++++++--------- src/nancy/store.py | 4 ++-- tests/test_db.py | 18 +++++++++--------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/nancy/fs.py b/src/nancy/fs.py index a3996d6..b87dcd9 100644 --- a/src/nancy/fs.py +++ b/src/nancy/fs.py @@ -174,14 +174,14 @@ class FSEntry: @classmethod def from_db_index(cls, cursor, root_id=None, root_row=None): - """Given id of an entry in store_file, recursively fill this object""" + """Given id of an entry in filedir, recursively fill this object""" fields = '(id, filename, filetype, unfrozen_perms, frozen, sha256, symlink_target)' if root_row is None: - cursor.execute(f'SELECT {fields} FROM store_file WHERE id={root_id};') + cursor.execute(f'SELECT {fields} FROM filedir WHERE id={root_id};') root_row = cursor.fetchone() root_id, name, filetype, unfrozen_perms, frozen, sha256, symlink_target = root_row # get children - cursor.execute(f'SELECT {fields} FROM store_file WHERE parent={root_id} ORDER BY name;') + cursor.execute(f'SELECT {fields} FROM filedir WHERE parent={root_id} ORDER BY name;') rows = cursor.fetchall() return cls( name=name, diff --git a/src/nancy/schema/version0.sql b/src/nancy/schema/version0.sql index d56a7f8..af0e098 100644 --- a/src/nancy/schema/version0.sql +++ b/src/nancy/schema/version0.sql @@ -70,14 +70,14 @@ CREATE TABLE store (id INTEGER PRIMARY KEY NOT NULL, FOREIGN KEY (machine) REFERENCES machine (id) ON UPDATE CASCADE ); --- The store_file table holds all files AND DIRECTORIES that are tracked by the +-- The filedir table holds all files and directories that are tracked by the -- store. Files and directories are distinguished by the filetype column. This -- table also holds tracked files and directories that have been imported and -- live outside the current store. -CREATE TABLE store_file (id INTEGER PRIMARY KEY NOT NULL, +CREATE TABLE filedir (id INTEGER PRIMARY KEY NOT NULL, store INTEGER NOT NULL, filename TEXT, -- only a filename, not a path - parent INTEGER REFERENCES store_file ON UPDATE CASCADE, + parent INTEGER REFERENCES filedir ON UPDATE CASCADE, frozen BOOL NOT NULL, filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details @@ -95,23 +95,23 @@ CREATE TABLE store_file (id INTEGER PRIMARY KEY NOT NULL, FOREIGN KEY (source_datum) REFERENCES datum (id) ON UPDATE CASCADE, FOREIGN KEY (source_program) REFERENCES program (id) ON UPDATE CASCADE ); -CREATE TRIGGER insert_store_file BEFORE INSERT ON store_file +CREATE TRIGGER insert_filedir BEFORE INSERT ON filedir BEGIN SELECT CASE - --WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM store_file WHERE id = NEW.parent) != 'DIR' + --WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR' --THEN RAISE (ABORT, 'Parent is not listed as a directory') - WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM store_file WHERE id = NEW.parent) + WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent) THEN RAISE (ABORT, 'Parent directory resides in different store') END; END; -CREATE TRIGGER update_store_file BEFORE UPDATE ON store_file +CREATE TRIGGER update_filedir BEFORE UPDATE ON filedir BEGIN SELECT CASE - --WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM store_file WHERE id = NEW.parent) != 'DIR' + --WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR' --THEN RAISE (ABORT, 'Parent is not listed as a directory') - WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM store_file WHERE id = NEW.parent) + WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent) THEN RAISE (ABORT, 'Parent directory resides in different store') END; END; diff --git a/src/nancy/store.py b/src/nancy/store.py index 901a18e..4ac4247 100644 --- a/src/nancy/store.py +++ b/src/nancy/store.py @@ -139,7 +139,7 @@ class Store: """Return recursive structure containing FSEntry objects from db""" # get the database id for the table entry in this store having name '.' cur = self.conn.cursor() - cur.execute('SELECT id FROM store_file WHERE store=0 AND parent is NULL;') + cur.execute('SELECT id FROM filedir WHERE store=0 AND parent is NULL;') root_id = cur.fetchone() if root_id is None: return fs.FSEntry.empty_root() @@ -166,7 +166,7 @@ class Store: # create entries for all directories if they do not yet exist (top # down) - # insert files and symlinks into store_file, computing checksums on + # insert files and symlinks into filedir, computing checksums on # each # update versions in nancy.db as appropriate diff --git a/tests/test_db.py b/tests/test_db.py index 12c16e9..0dc3605 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -151,13 +151,13 @@ def insert_store(insert_machine): def insert_directories(insert_store): cur = insert_store cur.executemany( - 'INSERT INTO store_file VALUES ' + 'INSERT INTO filedir VALUES ' '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [( None, #id INTEGER PRIMARY KEY NOT NULL, 1, #store INTEGER NOT NULL, '.', #filename TEXT, -- only a filename, not a path - None, #parent INTEGER REFERENCES store_file ON UPDATE CASCADE, + None, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE, False, #frozen BOOL NOT NULL, 'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details 'dr-xr-xr--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--' @@ -169,7 +169,7 @@ def insert_directories(insert_store): None, #id INTEGER PRIMARY KEY NOT NULL, 1, #store INTEGER NOT NULL, 'foo', #filename TEXT, -- only a filename, not a path - 1, #parent INTEGER REFERENCES store_file ON UPDATE CASCADE, + 1, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE, False, #frozen BOOL NOT NULL, 'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details 'dr-xr-xr--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--' @@ -181,7 +181,7 @@ def insert_directories(insert_store): None, #id INTEGER PRIMARY KEY NOT NULL, 2, #store INTEGER NOT NULL, '.', #filename TEXT, -- only a filename, not a path - None, #parent INTEGER REFERENCES store_file ON UPDATE CASCADE, + None, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE, False, #frozen BOOL NOT NULL, 'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details 'dr-xr-xr--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--' @@ -198,13 +198,13 @@ def test_crossstore_directory_insert(insert_directories): with pytest.raises(sqlite3.IntegrityError): # declaring directory as belonging to store 2, but parent's store is 1 cur.execute( - 'INSERT INTO store_file VALUES ' + 'INSERT INTO filedir VALUES ' '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', ( None, #id INTEGER PRIMARY KEY NOT NULL, 2, #store INTEGER NOT NULL, - 'xstore_file', #filename TEXT, -- only a filename, not a path - 1, #parent INTEGER REFERENCES store_file ON UPDATE CASCADE, + 'some_filedir.txt', #filename TEXT, -- only a filename, not a path + 1, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE, False, #frozen BOOL NOT NULL, 'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details 'dr-xr-xr--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--' @@ -215,7 +215,7 @@ def test_crossstore_directory_insert(insert_directories): )) for row in cur.connection.iterdump(): print(row) - cur.execute('SELECT * FROM store_file') + cur.execute('SELECT * FROM filedir') print(cur.fetchall()) @@ -223,7 +223,7 @@ def test_crossstore_directory_insert(insert_directories): def insert_files(insert_directories): cur = insert_directories cur.executemany( - 'INSERT INTO store_file VALUES ' + 'INSERT INTO filedir VALUES ' '(?, ?, ?, ?, ?, ?, ?, ?)', [( None,