forked from modin-project/modin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX-modin-project#4479: Prevent users from using a local filepath whe…
…n performing a distributed write Signed-off-by: Rehan Durrani <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import pathlib | ||
import re | ||
|
||
S3_ADDRESS_REGEX = re.compile("[sS]3://(.*?)/(.*)") | ||
|
||
def is_local_path(path_or_buf) -> bool: | ||
""" | ||
Return True if the specified path_or_buf is a local path, False otherwise. | ||
Parameters | ||
---------- | ||
path_or_buf : str, path object or file-like object | ||
The path or buffer to check. | ||
Returns | ||
------- | ||
Whether the `path_or_buf` points to a local file. | ||
""" | ||
if isinstance(path_or_buf, str): | ||
if S3_ADDRESS_REGEX.match(path_or_buf) is not None or "://" in path_or_buf: | ||
return False # S3 or network path. | ||
if isinstance(path_or_buf, str) or isinstance(path_or_buf, pathlib.PurePath): | ||
return os.path.exists(path_or_buf) | ||
return False |