Skip to content

Commit 5e854b9

Browse files
committed
relink.py: Delete a redundant check.
handle_non_dir() doesn't need to check that path is under inputdata_root, because that is already checked in process_args.
1 parent 8b6491a commit 5e854b9

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

relink.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,21 @@ def _handle_non_dir_str(path: str, user_uid: int):
9393
return None
9494

9595

96-
def handle_non_dir(var, user_uid, inputdata_root):
96+
def handle_non_dir(var, user_uid):
9797
"""
9898
Check if a non-directory is owned by the user and should be processed. Passes var to a
9999
helper function depending on its type.
100100
101101
Args:
102102
var (os.DirEntry or str): A directory entry from os.scandir(), or a string path.
103103
user_uid (int): The UID of the user whose files to find.
104-
inputdata_root (str): The root of the directory tree containing CESM input data.
105104
106105
Returns:
107106
str or None: The absolute path to the file if it's owned by the user
108107
and is a regular file (not a symlink), otherwise None.
109108
110109
Raises:
111110
TypeError: If var is not a DirEntry-like object.
112-
ValueError: If the file path is not under inputdata_root.
113111
"""
114112

115113
# Handle a variable of type str.
@@ -130,12 +128,6 @@ def handle_non_dir(var, user_uid, inputdata_root):
130128
f"Unsure how to handle non-directory variable of type {type(var)}"
131129
)
132130

133-
# Check that resulting path is a child of inputdata_root
134-
if file_path is not None and not Path(file_path).is_relative_to(inputdata_root):
135-
raise ValueError(
136-
f"'{file_path}' must be equivalent to or under '{inputdata_root}"
137-
)
138-
139131
return file_path
140132

141133

@@ -169,7 +161,7 @@ def find_owned_files_scandir(item, user_uid, inputdata_root=DEFAULT_SOURCE_ROOT)
169161

170162
# Things other than directories are handled separately
171163
elif (
172-
entry_path := handle_non_dir(entry, user_uid, inputdata_root)
164+
entry_path := handle_non_dir(entry, user_uid)
173165
) is not None:
174166
yield entry_path
175167

@@ -178,7 +170,7 @@ def find_owned_files_scandir(item, user_uid, inputdata_root=DEFAULT_SOURCE_ROOT)
178170
continue
179171

180172
except NotADirectoryError:
181-
if (file_path := handle_non_dir(item, user_uid, inputdata_root)) is not None:
173+
if (file_path := handle_non_dir(item, user_uid)) is not None:
182174
yield file_path
183175

184176
except (OSError, PermissionError) as e:

tests/relink/test_handle_non_dir.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def test_works_with_direntry(self, temp_dirs):
382382
# Get DirEntry for the file
383383
with os.scandir(source_dir) as entries:
384384
entry = next(e for e in entries if e.name == "test.txt")
385-
result = relink.handle_non_dir(entry, user_uid, source_dir)
385+
result = relink.handle_non_dir(entry, user_uid)
386386

387387
assert result == test_file
388388

@@ -397,7 +397,7 @@ def test_works_with_str(self, temp_dirs):
397397
f.write("content")
398398

399399
# Get path of the file
400-
result = relink.handle_non_dir(test_file, user_uid, source_dir)
400+
result = relink.handle_non_dir(test_file, user_uid)
401401

402402
assert result == test_file
403403

@@ -412,7 +412,7 @@ def test_errors_with_str_file_doesnt_exist(self, temp_dirs):
412412

413413
# Get path of the file
414414
with pytest.raises(FileNotFoundError):
415-
relink.handle_non_dir(test_file, user_uid, source_dir)
415+
relink.handle_non_dir(test_file, user_uid)
416416

417417
def test_raises_typeerror_for_int(self, temp_dirs):
418418
"""Test that handle_non_dir raises TypeError for an integer."""
@@ -426,4 +426,4 @@ def test_raises_typeerror_for_int(self, temp_dirs):
426426
TypeError,
427427
match=f"Unsure how to handle non-directory variable of type.*{expected_type}",
428428
):
429-
relink.handle_non_dir(invalid_input, user_uid, source_dir)
429+
relink.handle_non_dir(invalid_input, user_uid)

0 commit comments

Comments
 (0)