Skip to content

Commit 605fc60

Browse files
committed
feat: implement get_specific_child
Search for a specific name under specified directory.
1 parent 540a393 commit 605fc60

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

db.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ def get_children(self, parent_rowid: int) -> list[tuple[int, str]]:
118118
)
119119
return res.fetchall()
120120

121+
def get_specific_child(self, parent_rowid: int, name: str) -> int | None:
122+
"""Get child in a folder.
123+
124+
:param parent_rowid: rowid of parent directory from fs table.
125+
:param name: name of the directory to search for.
126+
"""
127+
res = self.cur.execute(
128+
'SELECT rowid FROM fs WHERE parent = ? AND name = ?',
129+
(parent_rowid, name),
130+
)
131+
row = res.fetchone()
132+
if row is None:
133+
# path doesn't exist
134+
return None
135+
return row[0]
136+
137+
121138

122139
class DatabaseWriter(DatabaseCommon):
123140
"""Database with read-write support."""
@@ -404,6 +421,9 @@ def close(self):
404421
self.cur.execute(
405422
'CREATE INDEX IF NOT EXISTS parent_index ON fs (parent)'
406423
)
424+
self.cur.execute(
425+
'CREATE INDEX IF NOT EXISTS parent_name_index ON fs (parent, name)'
426+
)
407427
self.cur.execute(
408428
'CREATE INDEX IF NOT EXISTS selinux_type_index ON fs (selinux_type)'
409429
)

0 commit comments

Comments
 (0)