Allow existing empty dir when migrating files

Remove old empty directory if it exists - otherwise, we move old/data to
new/data/data.
This commit is contained in:
Florian Bruhin 2017-09-13 17:38:56 +02:00
parent 0498e042a0
commit f7d17c4c55
2 changed files with 6 additions and 4 deletions

View File

@ -359,9 +359,11 @@ def _move_data(old, new):
log.init.debug("Migrating data from {} to {}".format(old, new))
if os.path.exists(new):
message.error("Failed to move data from {} as {} already exists!"
.format(old, new))
return False
if os.listdir(new):
message.error("Failed to move data from {} as {} is non-empty!"
.format(old, new))
return False
os.rmdir(new)
try:
shutil.move(old, new)

View File

@ -389,7 +389,7 @@ class TestDataMigrations:
standarddir._move_webengine_data()
record = caplog.records[-1]
expected = "Failed to move data from {} as {} already exists!".format(
expected = "Failed to move data from {} as {} is non-empty!".format(
old_path, new_path)
assert record.message == expected