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

Persistent session storage #614

Merged
merged 6 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
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
9 changes: 3 additions & 6 deletions jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A base class session manager."""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import os
import pathlib
import uuid

Expand Down Expand Up @@ -47,14 +46,12 @@ def _validate_database_filepath(self, proposal):
raise TraitError(
"`database_filepath` expected a file path, but the given path is a directory."
)
# If the file exists, but it's empty, its a valid entry.
if os.stat(path).st_size == 0:
return value
# Verify that database path is an SQLite 3 Database by checking its header.
with open(value, "rb") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant also for the contents validation piece, rather than inspecting the file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sqlite3 overwrites the file if it's not a valid database format, rather than raising an exception if the file has contents that are not sqlite data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yup, confirmed.

header = f.read(100)
if not header.startswith(b"SQLite format 3"):
raise TraitError("The file does not look like ")

if not header.startswith(b"SQLite format 3") and not header == b"":
raise TraitError("The given file is not an SQLite database file.")
return value

kernel_manager = Instance("jupyter_server.services.kernels.kernelmanager.MappingKernelManager")
Expand Down