Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boolean sync argument to get_path() #20

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions jupyter_server_fileid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ def _update(self, id, stat_info=None, path=None):
)
return

def sync_all(self):
"""
Syncs Files table with the filesystem and ensures that the correct path
is associated with each file ID. Required to be called manually
beforehand if `sync=False` is passed to `get_path()`.

Notes
-----
- Identical to `_sync_all()`, but is public and commits the transaction
upon invocation. See `_sync_all()` for more implementation details."""
self._sync_all()
self.con.commit()

def index(self, path, stat_info=None, commit=True):
"""Returns the file ID for the file at `path`, creating a new file ID if
one does not exist. Returns None only if file does not exist at path."""
Expand Down Expand Up @@ -394,12 +407,25 @@ def get_id(self, path):
self.con.commit()
return id

def get_path(self, id):
def get_path(self, id, sync=True):
"""Retrieves the file path associated with a file ID. Returns None if
the ID does not exist in the Files table or if the corresponding path no
longer has a file."""
self._sync_all()
self.con.commit()
longer has a file.

Parameters
----------
sync : bool
Whether to invoke `sync_all()` automatically prior to ID lookup.

Notes
-----
- For performance reasons, if this method must be called multiple times
in serial, then it is best to first invoke `sync_all()` and then call
this method with the argument `sync=False`.
"""
if sync:
self.sync_all()

row = self.con.execute("SELECT path, ino FROM Files WHERE id = ?", (id,)).fetchone()

# if no record associated with ID, return None
Expand Down