Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Replace os.rename with shutil.move #48

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions terrarium/terrarium.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def restore_previously_backed_up_environment(self):
rmtree(target)

logger.info('Renaming %s to %s', backup, target)
os.rename(backup, target)
if backup != target:
shutil.move(backup, target)
return 0

def get_target_location(self):
Expand Down Expand Up @@ -233,15 +234,18 @@ def install(self):
old_target_backup = os.path.join(old_target_backup, prompt)
logger.info(
'Backing environment up to %s' % old_target_backup)
try:
os.rename(old_target, old_target_backup)
except OSError, why:
logger.error(
'Failed to move environment out of the way. '
'Check that you have the correct permissions. '
'%s' % why
)
return 1
if old_target != old_target_backup:
try:
msg = 'Renaming %s to %s'
logger.info(msg, old_target, old_target_backup)
shutil.move(old_target, old_target_backup)
except OSError, why:
logger.error(
'Failed to move environment out of the way. '
'Check that you have the correct permissions. '
'%s' % why
)
return 1

# Fix paths
Terrarium.replace_all_in_directory(
Expand All @@ -250,16 +254,18 @@ def install(self):
old_target,
)

try:
# move the new environment into the target's place
os.rename(new_target, old_target)
except OSError, why:
logger.error(
'Failed to move the new environment into the correct path. '
'Check that you have the correct permissions. '
'%s' % why
)
return 1
if new_target != old_target:
try:
# move the new environment into the target's place
logger.info('Renaming %s to %s', new_target, old_target)
shutil.move(new_target, old_target)
except OSError, why:
logger.error(
'Failed to move the new environment into the correct path.'
' Check that you have the correct permissions. '
'%s' % why
)
return 1

# Do we keep a backup of the old environment around or wipe it?
if os.path.isdir(old_target_backup) and not self.args.backup:
Expand Down