Improve a few uses of pathclass.

This commit is contained in:
voussoir 2021-12-07 12:41:58 -08:00
parent f2190b9bfb
commit 90f14e04f8
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -556,7 +556,7 @@ def copy_file(
log.debug('Closing dest handle.') log.debug('Closing dest handle.')
destination_handle.close() destination_handle.close()
log.debug('Copying metadata.') log.debug('Copying metadata.')
shutil.copystat(source.absolute_path, destination.absolute_path) shutil.copystat(source, destination)
results.written = True results.written = True
if verify_hash: if verify_hash:
@ -712,12 +712,9 @@ def new_root(filepath, root):
I use this so that my G: drive can have backups from my C: and D: drives I use this so that my G: drive can have backups from my C: and D: drives
while preserving directory structure in G:\\D and G:\\C. while preserving directory structure in G:\\D and G:\\C.
''' '''
filepath = pathclass.Path(filepath).absolute_path filepath = pathclass.Path(filepath).absolute_path.replace(':', os.sep)
root = pathclass.Path(root).absolute_path new_path = pathclass.Path(root).join(filepath)
filepath = filepath.replace(':', os.sep) return new_path
filepath = os.path.normpath(filepath)
filepath = os.path.join(root, filepath)
return pathclass.Path(filepath)
def normalize(text): def normalize(text):
''' '''
@ -746,6 +743,9 @@ def verify_hash(
known_size: known_size:
Optional, should be the previously known integer number of bytes. Optional, should be the previously known integer number of bytes.
This makes failing the file much easier if the sizes differ. This makes failing the file much easier if the sizes differ.
**hash_kwargs:
Passed into `hash_file`.
''' '''
path = pathclass.Path(path) path = pathclass.Path(path)
path.assert_is_file() path.assert_is_file()