Skip to content

Commit

Permalink
Merge pull request #95 from DataONEorg/feature-94-client-bugfix
Browse files Browse the repository at this point in the history
Feature-94: Client Bug Fixes
  • Loading branch information
doulikecookiedough authored May 23, 2024
2 parents 31aa090 + 63ad53c commit 2ed6340
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/hashstore/filehashstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def __init__(self, properties=None):
self.objects = self.root + "/objects"
self.metadata = self.root + "/metadata"
self.refs = self.root + "/refs"
self.cids = self.refs + "/cids"
self.pids = self.refs + "/pids"
if not os.path.exists(self.objects):
self._create_path(self.objects + "/tmp")
if not os.path.exists(self.metadata):
Expand All @@ -128,7 +130,7 @@ def __init__(self, properties=None):
# Configuration and Related Methods

@staticmethod
def _load_properties(hahstore_yaml_path, hashstore_required_prop_keys):
def _load_properties(hashstore_yaml_path, hashstore_required_prop_keys):
"""Get and return the contents of the current HashStore configuration.
:return: HashStore properties with the following keys (and values):
Expand All @@ -138,7 +140,7 @@ def _load_properties(hahstore_yaml_path, hashstore_required_prop_keys):
- ``store_metadata_namespace`` (str): Namespace for the HashStore's system metadata.
:rtype: dict
"""
if not os.path.exists(hahstore_yaml_path):
if not os.path.exists(hashstore_yaml_path):
exception_string = (
"FileHashStore - load_properties: hashstore.yaml not found"
+ " in store root path."
Expand All @@ -147,7 +149,7 @@ def _load_properties(hahstore_yaml_path, hashstore_required_prop_keys):
raise FileNotFoundError(exception_string)

# Open file
with open(hahstore_yaml_path, "r", encoding="utf-8") as hs_yaml_file:
with open(hashstore_yaml_path, "r", encoding="utf-8") as hs_yaml_file:
yaml_data = yaml.safe_load(hs_yaml_file)

# Get hashstore properties
Expand Down Expand Up @@ -2167,9 +2169,9 @@ def _get_store_path(self, entity):
elif entity == "refs":
return Path(self.refs)
elif entity == "cid":
return Path(self.refs) / "cid"
return Path(self.cids)
elif entity == "pid":
return Path(self.refs) / "pid"
return Path(self.pids)
else:
raise ValueError(
f"entity: {entity} does not exist. Do you mean 'objects', 'metadata' or 'refs'?"
Expand Down Expand Up @@ -2210,9 +2212,9 @@ def _count(self, entity):
elif entity == "metadata":
directory_to_count = self.metadata
elif entity == "pid":
directory_to_count = self.refs + "/pid"
directory_to_count = self.pids
elif entity == "cid":
directory_to_count = self.refs + "/cid"
directory_to_count = self.cids
else:
raise ValueError(
f"entity: {entity} does not exist. Do you mean 'objects' or 'metadata'?"
Expand Down
10 changes: 10 additions & 0 deletions src/hashstore/hashstoreclient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""HashStore Command Line App"""

import logging
import os
from argparse import ArgumentParser
Expand Down Expand Up @@ -741,6 +742,13 @@ def main():
f"Missing config file (hashstore.yaml) at store path: {store_path}."
+ " HashStore must first be initialized, use `--help` for more information."
)
else:
# Get the default format_id for sysmeta
with open(store_path_config_yaml, "r", encoding="utf-8") as hs_yaml_file:
yaml_data = yaml.safe_load(hs_yaml_file)

default_formatid = yaml_data["store_metadata_namespace"]

# Setup logging, create log file if it doesn't already exist
hashstore_py_log = store_path + "/python_client.log"
python_log_file_path = Path(hashstore_py_log)
Expand Down Expand Up @@ -768,6 +776,8 @@ def main():
checksum_algorithm = getattr(args, "object_checksum_algorithm")
size = getattr(args, "object_size")
formatid = getattr(args, "object_formatid")
if formatid is None:
formatid = default_formatid
knbvm_test = getattr(args, "knbvm_flag")
# Instantiate HashStore Client
props = parser.load_store_properties(store_path_config_yaml)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filehashstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ def test_resolve_path_refs_pid(pids, store):
resolved_pid_ref_abs_path = store._resolve_path("pid", pid)
pid_refs_metadata_hashid = store._computehash(pid)
calculated_pid_ref_path = (
store.refs + "/pid/" + "/".join(store._shard(pid_refs_metadata_hashid))
store.pids + "/" + "/".join(store._shard(pid_refs_metadata_hashid))
)

assert resolved_pid_ref_abs_path == calculated_pid_ref_path
Expand All @@ -1072,6 +1072,6 @@ def test_resolve_path_refs_cid(pids, store):
cid = object_metadata.cid

resolved_cid_ref_abs_path = store._resolve_path("cid", cid)
calculated_cid_ref_path = store.refs + "/cid/" + "/".join(store._shard(cid))
calculated_cid_ref_path = store.cids + "/" + "/".join(store._shard(cid))

assert resolved_cid_ref_abs_path == calculated_cid_ref_path
10 changes: 6 additions & 4 deletions tests/test_filehashstore_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,15 +1243,17 @@ def test_store_and_delete_objects_100_pids_1_cid(store):
for i in range(1, upper_limit):
pid_modified = f"dou.test.{str(i)}"
store.store_object(pid_modified, path)
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/pid")]) == 100
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/cid")]) == 1
assert (
sum([len(files) for _, _, files in os.walk(store.root + "/refs/pids")]) == 100
)
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/cids")]) == 1
assert store._count("objects") == 1
# Delete
for i in range(1, upper_limit):
pid_modified = f"dou.test.{str(i)}"
store.delete_object(pid_modified)
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/pid")]) == 0
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/cid")]) == 0
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/pids")]) == 0
assert sum([len(files) for _, _, files in os.walk(store.root + "/refs/cids")]) == 0
assert store._count("objects") == 0


Expand Down

0 comments on commit 2ed6340

Please sign in to comment.