diff --git a/voussoirkit/configlayers.py b/voussoirkit/configlayers.py index 678f49a..e373f45 100644 --- a/voussoirkit/configlayers.py +++ b/voussoirkit/configlayers.py @@ -86,7 +86,7 @@ def load_file(filepath, defaults): needs_rewrite = False if user_config_exists: - with open(path.absolute_path, 'r', encoding='utf-8') as handle: + with path.open('r', encoding='utf-8') as handle: user_config = json.load(handle) (config, needs_rewrite) = layer_json(config, user_config) else: diff --git a/voussoirkit/quickid.py b/voussoirkit/quickid.py index 5ad5049..1cf2e74 100644 --- a/voussoirkit/quickid.py +++ b/voussoirkit/quickid.py @@ -36,11 +36,13 @@ def equal_file(filename1, filename2, *args, **kwargs): ''' Given two files, return True if they have the same quickid hash. ''' - filename1 = pathclass.Path(filename1).absolute_path - filename2 = pathclass.Path(filename2).absolute_path - if os.path.getsize(filename1) != os.path.getsize(filename2): + file1 = pathclass.Path(filename1) + file2 = pathclass.Path(filename2) + file1.assert_is_file() + file2.assert_is_file() + if file1.size != file2.size: return False - with open(filename1, 'rb') as handle1, open(filename2, 'rb') as handle2: + with file1.open('rb') as handle1, file2.open('rb') as handle2: return equal_handle(handle1, handle2, *args, **kwargs) def matches_handle(handle, other_id): @@ -65,8 +67,8 @@ def matches_file(filename, other_id): Given a file and a quickid hash, return True if the file matches that hash. ''' - filename = pathclass.Path(filename).absolute_path - with open(filename, 'rb') as handle: + file = pathclass.Path(filename) + with file.open('rb') as handle: return matches_handle(handle, other_id) def quickid_handle(handle, hashtype='md5', chunk_size=CHUNK_SIZE): @@ -96,8 +98,9 @@ def quickid_file(filename, *args, **kwargs): ''' Return the quickid hash for this file. ''' - filename = pathclass.Path(filename).absolute_path - with open(filename, 'rb') as handle: + file = pathclass.Path(filename) + file.assert_is_file() + with file.open('rb') as handle: return quickid_handle(handle, *args, **kwargs) def main(argv): diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index 24f6557..0c88b2f 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -438,7 +438,7 @@ def copy_file( def handlehelper(path, mode): try: - handle = open(path.absolute_path, mode) + handle = path.open(mode) return handle except PermissionError as exception: if callback_permission_denied is not None: @@ -548,7 +548,7 @@ def hash_file( checked_bytes = 0 file_size = os.path.getsize(path.absolute_path) - handle = open(path.absolute_path, 'rb') + handle = path.open('rb') with handle: while True: chunk = handle.read(chunk_size)