- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
          GH-73991: Support preserving metadata in pathlib.Path.copy()
          #120806
        
          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
          
     Merged
      
      
    
                
     Merged
            
            
          Conversation
  
    
      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
    
  
  
    
    Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`, defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like `shutil.copystat()`. The argument has no effect on Windows, where metadata is always copied. In the pathlib ABCs we copy the file permissions with `PathBase.chmod()` where supported. In the future we might want to support a more generic public interface for copying metadata between different types of `PathBase` object, but it would be premature here.
| 
 | 
    
  barneygale 
      added a commit
        to barneygale/cpython
      that referenced
      this pull request
    
      Jul 6, 2024 
    
    
      
  
    
      
    
  
Follow-up to python#120806. Use `os_helper.skip_unless_xattr` to skip testing xattr preservation when unsupported.
    
  barneygale 
      added a commit
      that referenced
      this pull request
    
      Jul 7, 2024 
    
    
  
    
  noahbkim 
      pushed a commit
        to hudson-trading/cpython
      that referenced
      this pull request
    
      Jul 11, 2024 
    
    
      
  
    
      
    
  
…ython#120806) Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`, defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like `shutil.copystat()`. The argument has no effect on Windows, where metadata is always copied. Internally (in the pathlib ABCs), path types gain `_readable_metadata` and `_writable_metadata` attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection of `source._readable_metadata` and `target._writable_metadata` to minimise reads/writes. A new `_read_metadata()` method accepts a set of metadata keys and returns a dict with those keys, and a new `_write_metadata()` method accepts a dict of metadata. We *might* make these public in future, but it's hard to justify while the ABCs are still private.
    
  noahbkim 
      pushed a commit
        to hudson-trading/cpython
      that referenced
      this pull request
    
      Jul 11, 2024 
    
    
      
  
    
      
    
  
…thon#121444) Follow-up to python#120806. Use `os_helper.skip_unless_xattr` to skip testing xattr preservation when unsupported.
    
  estyxx 
      pushed a commit
        to estyxx/cpython
      that referenced
      this pull request
    
      Jul 17, 2024 
    
    
      
  
    
      
    
  
…ython#120806) Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`, defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like `shutil.copystat()`. The argument has no effect on Windows, where metadata is always copied. Internally (in the pathlib ABCs), path types gain `_readable_metadata` and `_writable_metadata` attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection of `source._readable_metadata` and `target._writable_metadata` to minimise reads/writes. A new `_read_metadata()` method accepts a set of metadata keys and returns a dict with those keys, and a new `_write_metadata()` method accepts a dict of metadata. We *might* make these public in future, but it's hard to justify while the ABCs are still private.
    
  estyxx 
      pushed a commit
        to estyxx/cpython
      that referenced
      this pull request
    
      Jul 17, 2024 
    
    
      
  
    
      
    
  
…thon#121444) Follow-up to python#120806. Use `os_helper.skip_unless_xattr` to skip testing xattr preservation when unsupported.
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  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.
  
    
  
    
Add preserve_metadata keyword-only argument to
pathlib.Path.copy(), defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, likeshutil.copystat(). The argument has no effect on Windows, where metadata is always copied.Internally (in the pathlib ABCs), path types gain
_readable_metadataand_writable_metadataattributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection ofsource._readable_metadataandtarget._writable_metadatato minimise reads/writes. A new_read_metadata()method accepts a set of metadata keys and returns a dict with those keys, and a new_write_metadata()method accepts a dict of metadata. We might make these public in future, but it's hard to justify while the ABCs are still private.📚 Documentation preview 📚: https://cpython-previews--120806.org.readthedocs.build/