-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow relative paths in FCPath #40
Conversation
Code Review Agent Run #87dbbfActionable Suggestions - 3
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
filecache/file_cache_path.py
Outdated
if not FCPath._is_absolute(str(new_sub_path2)): | ||
raise ValueError( | ||
f'Derived path must be absolute, got {new_sub_path2}') | ||
new_sub_path = self._make_paths_absolute(sub_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider validating sub_path
before calling _make_paths_absolute()
to ensure it's not None
. While the type hint suggests Optional[StrOrPathOrSeqType]
, there's no explicit check.
Code suggestion
Check the AI-generated fix before applying
new_sub_path = self._make_paths_absolute(sub_path) | |
if sub_path is None: | |
sub_path = '' | |
new_sub_path = self._make_paths_absolute(sub_path) |
Code Review Run #87dbbf
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
filecache/file_cache_path.py
Outdated
if not FCPath._is_absolute(new_sub_path): | ||
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve()) | ||
.as_posix()) | ||
new_sub_paths.append(new_sub_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding validation for the resolved absolute path to ensure it stays within allowed directories for security. The current implementation could potentially allow access to sensitive files outside intended directories.
Code suggestion
Check the AI-generated fix before applying
if not FCPath._is_absolute(new_sub_path): | |
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve()) | |
.as_posix()) | |
new_sub_paths.append(new_sub_path) | |
if not FCPath._is_absolute(new_sub_path): | |
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve()) | |
.as_posix()) | |
base_dir = Path(self._path).parent.resolve() | |
resolved_path = Path(new_sub_path).resolve() | |
if not str(resolved_path).startswith(str(base_dir)): | |
raise ValueError(f'Path {new_sub_path} resolves outside allowed directory {base_dir}') | |
new_sub_paths.append(new_sub_path) |
Code Review Run #87dbbf
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType, | ||
new_sub_path), | ||
missing_ok=missing_ok, | ||
anonymous=self._anonymous, | ||
nthreads=nthreads, | ||
exception_on_fail=exception_on_fail, | ||
url_to_path=url_to_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider consolidating the duplicate unlink
call parameters into a dictionary to reduce code duplication and improve maintainability. The same parameter list appears in both branches of the if
statement.
Code suggestion
Check the AI-generated fix before applying
@@ -1088,21 +1088,19 @@
new_sub_path = self._make_paths_absolute(sub_path)
+ unlink_params = {
+ 'missing_ok': missing_ok,
+ 'anonymous': self._anonymous,
+ 'nthreads': nthreads,
+ 'exception_on_fail': exception_on_fail,
+ 'url_to_path': url_to_path
+ }
+
if isinstance(new_sub_path, (list, tuple)):
- return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType,
- new_sub_path),
- missing_ok=missing_ok,
- anonymous=self._anonymous,
- nthreads=nthreads,
- exception_on_fail=exception_on_fail,
- url_to_path=url_to_path)
+ return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType, new_sub_path),
+ **unlink_params)
- return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType,
- new_sub_path),
- missing_ok=missing_ok,
- anonymous=self._anonymous,
- nthreads=nthreads,
- exception_on_fail=exception_on_fail,
- url_to_path=url_to_path)
Code Review Run #87dbbf
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #40 +/- ##
==========================================
+ Coverage 92.93% 93.03% +0.10%
==========================================
Files 5 5
Lines 1784 1767 -17
Branches 370 359 -11
==========================================
- Hits 1658 1644 -14
+ Misses 75 70 -5
- Partials 51 53 +2 ☔ View full report in Codecov by Sentry. |
Code Review Agent Run #a438ceActionable Suggestions - 1
Review Details
|
nthreads = self._validate_nthreads(nthreads) | ||
|
||
new_sub_path = self._make_paths_absolute(sub_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider keeping the original order of operations where path validation happens before nthreads
validation. The current change could affect error handling flow since invalid paths would not be caught before validating thread count.
Code suggestion
Check the AI-generated fix before applying
@@ -1058,1060 +1058,1060 @@
- nthreads = self._validate_nthreads(nthreads)
- new_sub_path = self._make_paths_absolute(sub_path)
+ new_sub_path = self._make_paths_absolute(sub_path)
+ nthreads = self._validate_nthreads(nthreads)
Code Review Run #a438ce
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Code Review Agent Run #7d2767Actionable Suggestions - 1
Review Details
|
Code Review Agent Run Status
|
Fixed Issues
Summary of Changes
Known Problems
Summary by Bito
This PR enhances FCPath by implementing relative path support and simplifying path handling logic. It introduces as_absolute() and _make_paths_absolute() methods for automatic conversion of relative paths to absolute using expanduser() and resolve(). The changes include debug printing capabilities for path splitting operations and consolidate code paths for different path types. A comprehensive test suite validates file operations including retrieve, exists, get_local_path, upload, and unlink functionalities.Unit tests added: True
Estimated effort to review (1-5, lower is better): 3