Avoid copying file if dst is a directory.

Fixes bug 938153

`shutil.move` in Python 2.4 will fallback to copying the file if dst is
a directory. See http://bugs.python.org/issue1577.

Change-Id: I2390337d82db5a72fef0e63877401134b1dcca55
This commit is contained in:
Rick Harris
2012-02-21 22:00:03 +00:00
parent adaf9049c8
commit 043347267b
@@ -23,7 +23,6 @@ import os
import os.path
import pickle
import shlex
import shutil
import subprocess
import XenAPIPlugin
@@ -32,6 +31,12 @@ from pluginlib_nova import *
configure_logging('migration')
def move_file(item, src, dst):
"""Move file with logging."""
logging.debug('Moving %(item)s: %(src)s -> %(dst)s' % locals())
os.rename(src, dst)
def move_vhds_into_sr(session, args):
"""Moves the VHDs from their copied location to the SR"""
params = pickle.loads(exists(args, 'params'))
@@ -54,9 +59,7 @@ def move_vhds_into_sr(session, args):
old_base_copy_uuid)
new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid)
logging.debug('Moving base %s into %s' % (source_base_copy_path,
temp_vhd_path))
shutil.move(source_base_copy_path, new_base_copy_path)
move_file('base', source_base_copy_path, new_base_copy_path)
if 'old_cow_uuid' in params:
old_cow_uuid = params['old_cow_uuid']
@@ -65,9 +68,7 @@ def move_vhds_into_sr(session, args):
source_cow_path = "%s/%s.vhd" % (source_image_path, old_cow_uuid)
new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid)
logging.debug('Moving COW %s into %s' % (source_cow_path,
temp_vhd_path))
shutil.move(source_cow_path, new_cow_path)
move_file('COW', source_cow_path, new_cow_path)
# Link the COW to the base copy
logging.debug('Attaching COW to the base %s -> %s' %
@@ -77,11 +78,13 @@ def move_vhds_into_sr(session, args):
# NOTE(sirp): COW should be copied before base_copy to avoid
# snapwatchd GC'ing an unreferenced base copy VDI
logging.debug('Moving COW %s to %s' % (new_cow_path, sr_path))
shutil.move(new_cow_path, sr_path)
new_cow_sr_path = os.path.join(
sr_path, os.path.basename(new_cow_path))
move_file('COW', new_cow_path, new_cow_sr_path)
logging.debug('Moving base %s to %s' % (new_base_copy_path, sr_path))
shutil.move(new_base_copy_path, sr_path)
new_base_copy_sr_path = os.path.join(
sr_path, os.path.basename(new_base_copy_path))
move_file('base', new_base_copy_path, new_base_copy_sr_path)
logging.debug('Cleaning up source path %s' % source_image_path)
os.rmdir(source_image_path)