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.
|
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
|
- 2016 12 06
|
||||||
- Fixed bug where dry runs would still create directories
|
- Fixed bug where dry runs would still create directories
|
||||||
|
|
||||||
|
|
|
@ -392,16 +392,22 @@ def copy_file(
|
||||||
destination_location = os.path.split(destination.absolute_path)[0]
|
destination_location = os.path.split(destination.absolute_path)[0]
|
||||||
os.makedirs(destination_location, exist_ok=True)
|
os.makedirs(destination_location, exist_ok=True)
|
||||||
|
|
||||||
try:
|
def handlehelper(path, mode):
|
||||||
log.debug('Opening handles.')
|
try:
|
||||||
source_handle = open(source.absolute_path, 'rb')
|
handle = open(path.absolute_path, mode)
|
||||||
destination_handle = open(destination.absolute_path, 'wb')
|
return handle
|
||||||
except PermissionError as exception:
|
except PermissionError as exception:
|
||||||
if callback_permission_denied is not None:
|
if callback_permission_denied is not None:
|
||||||
callback_permission_denied(source, exception)
|
callback_permission_denied(path, exception)
|
||||||
return [destination, 0]
|
return None
|
||||||
else:
|
else:
|
||||||
raise
|
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:
|
if validate_hash:
|
||||||
hasher = HASH_CLASS()
|
hasher = HASH_CLASS()
|
||||||
|
|
Loading…
Reference in a new issue