- 
                Notifications
    
You must be signed in to change notification settings  - Fork 669
 
FIX-#4479: Prevent users from using a local filepath when performing a distributed write #4484
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
          
     Open
      
      
            RehanSD
  wants to merge
  16
  commits into
  modin-project:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
RehanSD:rehan/issues4479
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      aca8db5
              
                FIX-#4479: Prevent users from using a local filepath when performing …
              
              
                 e622fcf
              
                lint
              
              
                 be74c8e
              
                Fix docstring
              
              
                 7b1dff6
              
                Update modin/core/execution/ray/implementations/utils.py
              
              
                RehanSD a313a79
              
                Update modin/core/execution/ray/implementations/utils.py
              
              
                RehanSD 1dd8636
              
                Update modin/core/execution/ray/implementations/pandas_on_ray/io/io.py
              
              
                RehanSD 4191088
              
                Update modin/core/execution/ray/implementations/pandas_on_ray/io/io.py
              
              
                RehanSD 8c7120b
              
                Address review comments
              
              
                 dcadcf4
              
                Address review comments and fix util for non-local paths and non-exis…
              
              
                 b6552ba
              
                Update modin/core/io/utils.py
              
              
                 0608f9e
              
                Update modin/core/io/utils.py
              
              
                 cc80818
              
                Add testing
              
              
                 8081d9c
              
                Use fsspec and default to pandas
              
              
                 9c108af
              
                Use fsspec more and default to pandas
              
              
                 f1bc60a
              
                Add support for windows
              
              
                 a7acd81
              
                Fix windows support
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
| # Licensed to Modin Development Team under one or more contributor license agreements. | ||
| # See the NOTICE file distributed with this work for additional information regarding | ||
| # copyright ownership. The Modin Development Team licenses this file to you under the | ||
| # Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
| # compliance with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software distributed under | ||
| # the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific language | ||
| # governing permissions and limitations under the License. | ||
| 
     | 
||
| """Collection of utility functions for distributed io.""" | ||
| 
     | 
||
| import os | ||
| import pathlib | ||
| import re | ||
| from typing import Union | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| 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: | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| return False # S3 or network path. | ||
| if isinstance(path_or_buf, (str, pathlib.PurePath)): | ||
| if os.path.exists(path_or_buf): | ||
| return True | ||
| local_device_id = os.stat(os.getcwd()).st_dev | ||
| path_device_id = get_device_id(path_or_buf) | ||
| if path_device_id == local_device_id: | ||
| return True | ||
| return False | ||
| 
     | 
||
| 
     | 
||
| def get_device_id(path: Union[str, pathlib.PurePath]) -> Union[int, None]: | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| """ | ||
| Return the result of `os.stat(path).st_dev` for the portion of `path` that exists locally. | ||
| Parameters | ||
| ---------- | ||
| path : str, path object | ||
| The path to check. | ||
| Returns | ||
| ------- | ||
| The `st_dev` field of `os.stat` of the portion of the `path` that exists locally, None if no | ||
| part of the path exists locally. | ||
| """ | ||
| index = 1 | ||
| path_list = list(pathlib.Path(path).parts) | ||
| if path_list[0] == "/": | ||
| index += 1 | ||
| try: | ||
| os.stat(os.path.join(*path_list[:index])) | ||
| except: | ||
| return None | ||
| while os.path.exists(os.path.join(*path_list[:index])): | ||
| index += 1 | ||
| index -= 1 | ||
| return os.stat(os.path.join(*path_list[:index])).st_dev | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.