Skip to content

Commit

Permalink
fix(localfs): Prevent invalid cross-device link errors (#158)
Browse files Browse the repository at this point in the history
* fix(localfs): Prevent invalid cross-device link errors

* feat(gfs): Add u100/v100 vars
  • Loading branch information
devsjc authored Jun 19, 2024
1 parent 5fdc812 commit 372359c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/nwp_consumer/internal/inputs/noaa/ncar.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,6 @@ def parameterConformMap(self) -> dict[str, internal.OCFParameter]:
"r": internal.OCFParameter.RelativeHumidityAGL,
"u10_instant": internal.OCFParameter.WindUComponentAGL,
"v10_instant": internal.OCFParameter.WindVComponentAGL,
"u100_instant": internal.OCFParameter.WindUComponent100m,
"v100_instant": internal.OCFParameter.WindVComponent100m,
}
14 changes: 8 additions & 6 deletions src/nwp_consumer/internal/outputs/localfs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ def store(self, *, src: pathlib.Path, dst: pathlib.Path) -> pathlib.Path:
return dst

dst.parent.mkdir(parents=True, exist_ok=True)
# Delete the cache to avoid double storage
shutil.move(src=src, dst=dst)
shutil.copy(src=src, dst=dst)

nbytes = os.stat(dst).st_size
if nbytes != dst.stat().st_size:
if src.stat().st_size != dst.stat().st_size:
log.warn(
event="file size mismatch",
src=src.as_posix(),
dst=dst.as_posix(),
srcbytes=src.stat().st_size,
dstbytes=nbytes,
dstbytes=dst.stat().st_size,
)
else:
log.debug(
event="stored file locally",
src=src.as_posix(),
dst=dst.as_posix(),
nbytes=nbytes,
nbytes=dst.stat().st_size,
)

# Delete the cache to avoid double storage
src.unlink()

return dst

def listInitTimes(self, *, prefix: pathlib.Path) -> list[dt.datetime]:
Expand Down

0 comments on commit 372359c

Please sign in to comment.