Skip to content

Commit

Permalink
The script bfabric_setResourceStatus_available.py and other uses of…
Browse files Browse the repository at this point in the history
… `report_resource`, correctly search files which

  have a relative path starting with `/` as in the case of the legacy wrapper creator.
  • Loading branch information
leoschwarz committed Dec 16, 2024
1 parent ac4eb3f commit c071bd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Versioning currently follows `X.Y.Z` where

- The submitter ensures that workunits always get set to `processing`.

### Fixed

- The script `bfabric_setResourceStatus_available.py` and other uses of `report_resource`, correctly search files which
have a relative path starting with `/` as in the case of the legacy wrapper creator.

## \[1.13.11\] - 2024-12-13

### Fixed
Expand Down
11 changes: 10 additions & 1 deletion src/bfabric_scripts/feeder/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
from bfabric_scripts.feeder.file_attributes import get_file_attributes


def _make_relative(path: str) -> str:
# TODO this is a hack which is necessary due to behavior of the legacy wrapper_creator, hopefully no
# other code uses leading slashes to indicate relative paths but this will be seen later when refactoring this
# away.
# replaces any number of leading slashes with an empty string
return path.lstrip("/")


def report_resource(client: Bfabric, resource_id: int) -> ResultContainer:
"""Saves the provided resource's checksum, file size and available state."""
resource = Resource.find(id=resource_id, client=client)
Expand All @@ -19,7 +27,8 @@ def report_resource(client: Bfabric, resource_id: int) -> ResultContainer:
logger.error("Resource does not have a storage")
return ResultContainer([])

filename = Path(resource.storage["basepath"]) / resource["relativepath"]
relative_path = _make_relative(resource["relativepath"])
filename = Path(resource.storage["basepath"]) / relative_path
logger.info("Testing file: {}", filename)
if filename.is_file():
checksum, _, filesize, _ = get_file_attributes(str(filename))
Expand Down

0 comments on commit c071bd2

Please sign in to comment.