Fix PermissionError raised with Source from Destination
This commit is contained in:
parent
b1cbd2bb39
commit
35cef050c2
2 changed files with 19 additions and 10 deletions
|
@ -3,6 +3,9 @@ Spinal
|
|||
|
||||
A couple of tools for copying files and directories.
|
||||
|
||||
- 2017 03 12
|
||||
- Fix the PermissionDenied callback always being called with Source path even if the Destination is the one that caused the problem.
|
||||
|
||||
- 2016 12 06
|
||||
- Fixed bug where dry runs would still create directories
|
||||
|
||||
|
|
|
@ -392,17 +392,23 @@ def copy_file(
|
|||
destination_location = os.path.split(destination.absolute_path)[0]
|
||||
os.makedirs(destination_location, exist_ok=True)
|
||||
|
||||
def handlehelper(path, mode):
|
||||
try:
|
||||
log.debug('Opening handles.')
|
||||
source_handle = open(source.absolute_path, 'rb')
|
||||
destination_handle = open(destination.absolute_path, 'wb')
|
||||
handle = open(path.absolute_path, mode)
|
||||
return handle
|
||||
except PermissionError as exception:
|
||||
if callback_permission_denied is not None:
|
||||
callback_permission_denied(source, exception)
|
||||
return [destination, 0]
|
||||
callback_permission_denied(path, exception)
|
||||
return None
|
||||
else:
|
||||
raise
|
||||
|
||||
log.debug('Opening handles.')
|
||||
source_handle = handlehelper(source, 'rb')
|
||||
destination_handle = handlehelper(destination, 'wb')
|
||||
if None in (source_handle, destination_handle):
|
||||
return [destination, 0]
|
||||
|
||||
if validate_hash:
|
||||
hasher = HASH_CLASS()
|
||||
|
||||
|
|
Loading…
Reference in a new issue