Skip to content

Commit bda41d5

Browse files
committed
Prevent volume_name from being used for file paths
1 parent 33a98f3 commit bda41d5

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

riptide/config/service/volumes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ def process_additional_volumes(volumes: list[dict], project_folder: str):
4040

4141
# Create additional volumes as defined type, if not exist
4242
has_type_defined = "type" in vol
43+
stat_is_dir = True
4344
vol_type = vol["type"] if has_type_defined else VOLUME_TYPE_DIRECTORY
4445
try:
4546
stat = os.lstat(vol["host"])
46-
if S_ISDIR(stat.st_mode):
47+
stat_is_dir = S_ISDIR(stat.st_mode)
48+
if stat_is_dir:
4749
if vol_type == VOLUME_TYPE_FILE:
4850
raise IsADirectoryError(
4951
f"The file at `{vol['host']}` is a directory, but the volume is defined as a regular file."
@@ -64,5 +66,11 @@ def process_additional_volumes(volumes: list[dict], project_folder: str):
6466

6567
# If volume_name is specified, add it to the volume definition
6668
if "volume_name" in vol:
69+
# Prevent the user from accidentally defining a named volume for something where the host path is a file,
70+
# because named volumes can not be files.
71+
if vol_type == VOLUME_TYPE_FILE or not stat_is_dir:
72+
raise NotADirectoryError(
73+
f"The `volume_name` option can only be used for directory paths. `{vol['host']}` is not a directory."
74+
)
6775
out[vol["host"]]["name"] = vol["volume_name"]
6876
return out

riptide/tests/unit/config/service/volumes_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def test_process_additional_volumes_volume_name_with_type_directory(self):
165165
self.assertTrue(os.path.isdir(os.path.join(test_dir, "no2")))
166166
self.assertTrue(os.path.isdir(os.path.join(test_dir, "no3")))
167167

168-
@unittest.skip("todo")
169168
def test_process_additional_volumes_volume_name_with_type_file_defined(self):
170169
with TemporaryDirectory() as test_dir:
171170
input = [
@@ -175,7 +174,6 @@ def test_process_additional_volumes_volume_name_with_type_file_defined(self):
175174
with self.assertRaises(NotADirectoryError):
176175
process_additional_volumes(input, test_dir)
177176

178-
@unittest.skip("todo")
179177
def test_process_additional_volumes_volume_name_with_type_file_detected(self):
180178
with TemporaryDirectory() as test_dir:
181179
open(os.path.join(test_dir, "no1"), "a").close()

0 commit comments

Comments
 (0)