Skip to content

Commit d261f73

Browse files
committed
fix(volumecache): treat a scalar dirs path as a single directory
Passing dirs as a bare string/Path (e.g. dirs="/root/.cache") iterated it character by character, putting entries like "/" into _dirs and making sync/hydrate walk far broader paths than intended. Normalize scalar str/bytes/PathLike input to a one-element list. Addresses capy-ai review on PR #531.
1 parent 0883400 commit d261f73

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

runpod/serverless/utils/rp_volume_cache.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class VolumeCache:
5757
_EXCLUDE_SUBSTRINGS = (os.sep + "refs" + os.sep, os.sep + ".no_exist" + os.sep)
5858

5959
def __init__(self, dirs, *, namespace=None, volume_path="/runpod-volume", best_effort=True):
60+
if isinstance(dirs, (str, bytes, os.PathLike)):
61+
# A bare path is one directory, not an iterable of path characters:
62+
# `dirs="/root/.cache"` must not be split into "/", "r", "o", ...
63+
dirs = [dirs]
6064
self._dirs = [os.path.realpath(os.fspath(d)) for d in dirs]
6165
self._namespace = namespace or os.environ.get("RUNPOD_ENDPOINT_ID") or ""
6266
if self._namespace and (

tests/test_serverless/test_utils/test_rp_volume_cache.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ def test_namespace_accepts_normal_value(tmp_path):
7878
assert vc._namespace == "ep1"
7979

8080

81+
def test_scalar_dirs_path_is_treated_as_single_dir(tmp_path):
82+
# A bare string/Path must be one directory, not iterated character-by-character
83+
# (which would put "/" and other roots into _dirs).
84+
vol = tmp_path / "volume"
85+
vol.mkdir()
86+
cache = tmp_path / "cache"
87+
expected = [os.path.realpath(str(cache))]
88+
89+
vc_str = VolumeCache(str(cache), namespace="ep1", volume_path=str(vol))
90+
assert vc_str._dirs == expected
91+
92+
vc_path = VolumeCache(cache, namespace="ep1", volume_path=str(vol)) # os.PathLike
93+
assert vc_path._dirs == expected
94+
95+
vc_list = VolumeCache([str(cache)], namespace="ep1", volume_path=str(vol))
96+
assert vc_list._dirs == expected # list input still works
97+
98+
8199
# --------------------------------------------------------------------------- #
82100
# sync -> hydrate round trip
83101
# --------------------------------------------------------------------------- #

0 commit comments

Comments
 (0)