Skip to content

Commit

Permalink
Merge branch 'main' into u/jrbogart/specify_prod_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanneBogart committed May 29, 2024
2 parents 179ac6a + b54ba6e commit 50bdea6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ its associated production schema and form foreign key constraints correctly.
Bumped database version to 2.3.0. This code requires
database version >= 2.3.0

## Version 0.4.2

- Add check during dataset registration to raise an exception if the `root_dir`
does not exist
- Add check before copying any data (i.e., `old_location != None`) that the
user has write permission to the `root_dir` folder.

## Version 0.4.1

Add ability to register "external" datasets. For example datasets that are not
Expand Down
2 changes: 1 addition & 1 deletion src/dataregistry/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.0"
15 changes: 15 additions & 0 deletions src/dataregistry/registrar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def __init__(self, db_connection, root_dir, owner, owner_type, execution_table):
self.which_table = "dataset"
self.entry_id = "dataset_id"

# Does the root_dir exist?
self.root_dir_exists = os.path.isdir(root_dir)

# Does the user have write permission to the root_dir?
self.root_dir_write_access = os.access(root_dir, os.W_OK)

def register(
self,
relative_path,
Expand Down Expand Up @@ -121,6 +127,10 @@ def register(
The execution ID associated with the dataset
"""

# If the root_dir does not exist, stop
if not self.root_dir_exists:
raise FileNotFoundError(f"root_dir {self._root_dir} does not exist")

# If external dataset, check for either a `url` or `contact_email`
if location_type == "external":
if url is None and contact_email is None:
Expand Down Expand Up @@ -369,6 +379,11 @@ def _handle_data(self, relative_path, old_location, owner, owner_type, verbose):

# Copy data into data registry
if old_location:

# Stop if we don't have write permission to the root_dir
if not self.root_dir_write_access:
raise Exception(f"Cannot copy data, no write access to {self._root_dir}")

if verbose:
tic = time.time()
print(
Expand Down

0 comments on commit 50bdea6

Please sign in to comment.