Rename store_file table to filedir
This commit is contained in:
parent
a5cbce3c66
commit
8d6395ecd1
@ -174,14 +174,14 @@ class FSEntry:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db_index(cls, cursor, root_id=None, root_row=None):
|
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)'
|
fields = '(id, filename, filetype, unfrozen_perms, frozen, sha256, symlink_target)'
|
||||||
if root_row is None:
|
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_row = cursor.fetchone()
|
||||||
root_id, name, filetype, unfrozen_perms, frozen, sha256, symlink_target = root_row
|
root_id, name, filetype, unfrozen_perms, frozen, sha256, symlink_target = root_row
|
||||||
# get children
|
# 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()
|
rows = cursor.fetchall()
|
||||||
return cls(
|
return cls(
|
||||||
name=name,
|
name=name,
|
||||||
|
|||||||
@ -70,14 +70,14 @@ CREATE TABLE store (id INTEGER PRIMARY KEY NOT NULL,
|
|||||||
FOREIGN KEY (machine) REFERENCES machine (id) ON UPDATE CASCADE
|
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
|
-- store. Files and directories are distinguished by the filetype column. This
|
||||||
-- table also holds tracked files and directories that have been imported and
|
-- table also holds tracked files and directories that have been imported and
|
||||||
-- live outside the current store.
|
-- 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,
|
store INTEGER NOT NULL,
|
||||||
filename TEXT, -- only a filename, not a path
|
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,
|
frozen BOOL NOT NULL,
|
||||||
filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
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_datum) REFERENCES datum (id) ON UPDATE CASCADE,
|
||||||
FOREIGN KEY (source_program) REFERENCES program (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
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
CASE
|
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')
|
--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')
|
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
CREATE TRIGGER update_store_file BEFORE UPDATE ON store_file
|
CREATE TRIGGER update_filedir BEFORE UPDATE ON filedir
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
CASE
|
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')
|
--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')
|
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
|
|||||||
@ -139,7 +139,7 @@ class Store:
|
|||||||
"""Return recursive structure containing FSEntry objects from db"""
|
"""Return recursive structure containing FSEntry objects from db"""
|
||||||
# get the database id for the table entry in this store having name '.'
|
# get the database id for the table entry in this store having name '.'
|
||||||
cur = self.conn.cursor()
|
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()
|
root_id = cur.fetchone()
|
||||||
if root_id is None:
|
if root_id is None:
|
||||||
return fs.FSEntry.empty_root()
|
return fs.FSEntry.empty_root()
|
||||||
@ -166,7 +166,7 @@ class Store:
|
|||||||
# create entries for all directories if they do not yet exist (top
|
# create entries for all directories if they do not yet exist (top
|
||||||
# down)
|
# down)
|
||||||
|
|
||||||
# insert files and symlinks into store_file, computing checksums on
|
# insert files and symlinks into filedir, computing checksums on
|
||||||
# each
|
# each
|
||||||
|
|
||||||
# update versions in nancy.db as appropriate
|
# update versions in nancy.db as appropriate
|
||||||
|
|||||||
@ -151,13 +151,13 @@ def insert_store(insert_machine):
|
|||||||
def insert_directories(insert_store):
|
def insert_directories(insert_store):
|
||||||
cur = insert_store
|
cur = insert_store
|
||||||
cur.executemany(
|
cur.executemany(
|
||||||
'INSERT INTO store_file VALUES '
|
'INSERT INTO filedir VALUES '
|
||||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
[(
|
[(
|
||||||
None, #id INTEGER PRIMARY KEY NOT NULL,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
1, #store INTEGER NOT NULL,
|
1, #store INTEGER NOT NULL,
|
||||||
'.', #filename TEXT, -- only a filename, not a path
|
'.', #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,
|
False, #frozen BOOL NOT NULL,
|
||||||
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
'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--'
|
'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,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
1, #store INTEGER NOT NULL,
|
1, #store INTEGER NOT NULL,
|
||||||
'foo', #filename TEXT, -- only a filename, not a path
|
'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,
|
False, #frozen BOOL NOT NULL,
|
||||||
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
'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--'
|
'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,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
2, #store INTEGER NOT NULL,
|
2, #store INTEGER NOT NULL,
|
||||||
'.', #filename TEXT, -- only a filename, not a path
|
'.', #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,
|
False, #frozen BOOL NOT NULL,
|
||||||
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
'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--'
|
'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):
|
with pytest.raises(sqlite3.IntegrityError):
|
||||||
# declaring directory as belonging to store 2, but parent's store is 1
|
# declaring directory as belonging to store 2, but parent's store is 1
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'INSERT INTO store_file VALUES '
|
'INSERT INTO filedir VALUES '
|
||||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
(
|
(
|
||||||
None, #id INTEGER PRIMARY KEY NOT NULL,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
2, #store INTEGER NOT NULL,
|
2, #store INTEGER NOT NULL,
|
||||||
'xstore_file', #filename TEXT, -- only a filename, not a path
|
'some_filedir.txt', #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,
|
False, #frozen BOOL NOT NULL,
|
||||||
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
'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--'
|
'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():
|
for row in cur.connection.iterdump():
|
||||||
print(row)
|
print(row)
|
||||||
cur.execute('SELECT * FROM store_file')
|
cur.execute('SELECT * FROM filedir')
|
||||||
print(cur.fetchall())
|
print(cur.fetchall())
|
||||||
|
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ def test_crossstore_directory_insert(insert_directories):
|
|||||||
def insert_files(insert_directories):
|
def insert_files(insert_directories):
|
||||||
cur = insert_directories
|
cur = insert_directories
|
||||||
cur.executemany(
|
cur.executemany(
|
||||||
'INSERT INTO store_file VALUES '
|
'INSERT INTO filedir VALUES '
|
||||||
'(?, ?, ?, ?, ?, ?, ?, ?)',
|
'(?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
[(
|
[(
|
||||||
None,
|
None,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user