Sync pull: Make a backup copy of the files before overwriting them
This commit is contained in:
parent
4cdf2cee9c
commit
9044bfadb9
@ -209,9 +209,6 @@ class PILLAR_OT_sync(async_loop.AsyncModalOperatorMixin, bpy.types.Operator):
|
|||||||
self.log.warning('Unable to find node on Blender Cloud for %s', fname)
|
self.log.warning('Unable to find node on Blender Cloud for %s', fname)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Download the file
|
|
||||||
file_id = node.properties.file
|
|
||||||
|
|
||||||
def file_downloaded(file_path: str, file_desc: pillarsdk.File):
|
def file_downloaded(file_path: str, file_desc: pillarsdk.File):
|
||||||
# Move the file next to the final location; as it may be on a
|
# Move the file next to the final location; as it may be on a
|
||||||
# different filesystem than the temporary directory, this can
|
# different filesystem than the temporary directory, this can
|
||||||
@ -219,17 +216,25 @@ class PILLAR_OT_sync(async_loop.AsyncModalOperatorMixin, bpy.types.Operator):
|
|||||||
local_temp = config_dir / (fname + '~')
|
local_temp = config_dir / (fname + '~')
|
||||||
local_final = config_dir / fname
|
local_final = config_dir / fname
|
||||||
|
|
||||||
self.log.info('Moving %s to %s', file_path, local_temp)
|
# Make a backup copy of the file as it was before pulling.
|
||||||
shutil.move(str(file_path), str(local_temp))
|
if local_final.exists():
|
||||||
self.log.info('Moving %s to %s', local_temp, local_final)
|
local_bak = config_dir / (fname + '-pre-bcloud-pull')
|
||||||
shutil.move(str(local_temp), str(local_final))
|
self.move_file(local_final, local_bak)
|
||||||
|
|
||||||
|
self.move_file(file_path, local_temp)
|
||||||
|
self.move_file(local_temp, local_final)
|
||||||
|
|
||||||
|
file_id = node.properties.file
|
||||||
await pillar.download_file_by_uuid(file_id,
|
await pillar.download_file_by_uuid(file_id,
|
||||||
temp_dir,
|
temp_dir,
|
||||||
str(meta_path),
|
str(meta_path),
|
||||||
file_loaded=file_downloaded,
|
file_loaded=file_downloaded,
|
||||||
future=self.signalling_future)
|
future=self.signalling_future)
|
||||||
|
|
||||||
|
def move_file(self, src, dst):
|
||||||
|
self.log.info('Moving %s to %s', src, dst)
|
||||||
|
shutil.move(str(src), str(dst))
|
||||||
|
|
||||||
async def reload_after_pull(self):
|
async def reload_after_pull(self):
|
||||||
self.report({'WARNING'}, 'Settings pulled from Blender Cloud, reloading.')
|
self.report({'WARNING'}, 'Settings pulled from Blender Cloud, reloading.')
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
Reference in New Issue
Block a user