9
9
10
10
11
11
class StatStruct :
12
- empty = True
13
12
ino : int
14
13
crtime : Optional [int ]
15
14
mtime : int
@@ -64,8 +63,8 @@ def __init__(self, *args, **kwargs):
64
63
")"
65
64
)
66
65
self ._index_all ()
66
+ # no need to index ino as it is autoindexed by sqlite via UNIQUE constraint
67
67
self .con .execute ("CREATE INDEX IF NOT EXISTS ix_Files_path ON Files (path)" )
68
- self .con .execute ("CREATE INDEX IF NOT EXISTS ix_Files_ino ON Files (ino)" )
69
68
self .con .execute ("CREATE INDEX IF NOT EXISTS ix_Files_is_dir ON Files (is_dir)" )
70
69
self .con .commit ()
71
70
@@ -138,7 +137,8 @@ def _sync_dir(self, dir_path):
138
137
stat_info = self ._parse_raw_stat (entry .stat ())
139
138
id , is_dirty_dir = self ._sync_file (entry .path , stat_info )
140
139
141
- if id is None :
140
+ # if entry is unindexed directory, create new record
141
+ if stat_info .is_dir and id is None :
142
142
self ._create (entry .path , stat_info )
143
143
144
144
# sync dirty dir contents if it is either unindexed or
@@ -201,13 +201,11 @@ def _normalize_path(self, path):
201
201
path = os .path .normpath (path )
202
202
return path
203
203
204
- def _parse_raw_stat (self , raw_stat , stat_info = None ):
204
+ def _parse_raw_stat (self , raw_stat ):
205
205
"""Accepts an `os.stat_result` object and returns a `StatStruct`
206
- object. Writes to `stat_info` argument if passed."""
207
- if stat_info is None :
208
- stat_info = StatStruct ()
206
+ object."""
207
+ stat_info = StatStruct ()
209
208
210
- stat_info .empty = False
211
209
stat_info .ino = raw_stat .st_ino
212
210
stat_info .crtime = (
213
211
raw_stat .st_ctime_ns
@@ -225,14 +223,12 @@ def _parse_raw_stat(self, raw_stat, stat_info=None):
225
223
def _stat (self , path ):
226
224
"""Returns stat info on a path in a StatStruct object.Returns None if
227
225
file does not exist at path."""
228
- stat_info = StatStruct ()
229
-
230
226
try :
231
227
raw_stat = os .stat (path )
232
228
except OSError :
233
229
return None
234
230
235
- return self ._parse_raw_stat (raw_stat , stat_info )
231
+ return self ._parse_raw_stat (raw_stat )
236
232
237
233
def _create (self , path , stat_info ):
238
234
"""Creates a record given its path and stat info. Returns the new file
@@ -300,6 +296,7 @@ def get_path(self, id):
300
296
the ID does not exist in the Files table or if the corresponding path no
301
297
longer has a file."""
302
298
self ._sync_all ()
299
+ self .con .commit ()
303
300
row = self .con .execute ("SELECT path FROM Files WHERE id = ?" , (id ,)).fetchone ()
304
301
return row [0 ] if row else None
305
302
0 commit comments