Skip to content

Commit 50dec2e

Browse files
authored
remove mtime fallback (#47)
1 parent 39040c2 commit 50dec2e

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

jupyter_server_fileid/manager.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,6 @@ def _sync_dir(self, dir_path):
547547

548548
scan_iter.close()
549549

550-
def _check_timestamps(self, stat_info, src_crtime, src_mtime):
551-
"""Returns True if the timestamps of a file match those recorded in the
552-
Files table. Returns False otherwise."""
553-
554-
src_timestamp = src_crtime if src_crtime is not None else src_mtime
555-
dst_timestamp = stat_info.crtime if stat_info.crtime is not None else stat_info.mtime
556-
return src_timestamp == dst_timestamp
557-
558550
def _sync_file(self, path, stat_info):
559551
"""
560552
Syncs the file at `path` with the Files table by detecting whether the
@@ -588,16 +580,16 @@ def _sync_file(self, path, stat_info):
588580
return None
589581

590582
src = self.con.execute(
591-
"SELECT id, path, crtime, mtime FROM Files WHERE ino = ?", (stat_info.ino,)
583+
"SELECT id, path, crtime FROM Files WHERE ino = ?", (stat_info.ino,)
592584
).fetchone()
593585

594586
# if ino is not in database, return None
595587
if src is None:
596588
return None
597-
id, old_path, crtime, mtime = src
589+
id, old_path, crtime = src
598590

599591
# if timestamps don't match, delete existing record and return None
600-
if not self._check_timestamps(stat_info, crtime, mtime):
592+
if crtime != stat_info.crtime:
601593
self.con.execute("DELETE FROM Files WHERE id = ?", (id,))
602594
return None
603595

@@ -744,21 +736,17 @@ def get_path(self, id):
744736
# optimistic approach: first check to see if path was not yet moved
745737
for retry in [True, False]:
746738
row = self.con.execute(
747-
"SELECT path, ino, crtime, mtime FROM Files WHERE id = ?", (id,)
739+
"SELECT path, ino, crtime FROM Files WHERE id = ?", (id,)
748740
).fetchone()
749741

750742
# if file ID does not exist, return None
751743
if not row:
752744
return None
753745

754-
path, ino, crtime, mtime = row
746+
path, ino, crtime = row
755747
stat_info = self._stat(path)
756748

757-
if (
758-
stat_info
759-
and ino == stat_info.ino
760-
and self._check_timestamps(stat_info, crtime, mtime)
761-
):
749+
if stat_info and ino == stat_info.ino and crtime == stat_info.crtime:
762750
# if file already exists at path and the ino and timestamps match,
763751
# then return the correct path immediately (best case)
764752
return self._from_normalized_path(path)

tests/test_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def test_index_oob_move(fid_manager, old_path, new_path, fs_helpers):
209209
assert fid_manager.index(new_path) == id
210210

211211

212+
crtime_support = os.name == "nt" or hasattr(os.stat_result, "st_birthtime")
213+
214+
215+
@pytest.mark.skipif(not crtime_support, reason="Requires crtime support.")
212216
def test_index_after_deleting_dir_in_same_path(fid_manager, test_path, fs_helpers):
213217
old_id = fid_manager.index(test_path)
214218

@@ -221,6 +225,7 @@ def test_index_after_deleting_dir_in_same_path(fid_manager, test_path, fs_helper
221225
assert fid_manager.get_path(new_id) == test_path
222226

223227

228+
@pytest.mark.skipif(not crtime_support, reason="Requires crtime support.")
224229
def test_index_after_deleting_regfile_in_same_path(fid_manager, test_path_child, fs_helpers):
225230
old_id = fid_manager.index(test_path_child)
226231

0 commit comments

Comments
 (0)