Include path separator and absolute path when checking if destination is a child of the source. Fixes gh-287

This commit is contained in:
Jaisen Mathai 2018-12-01 20:25:04 -08:00
parent 3f96e09126
commit 91bf181575
2 changed files with 18 additions and 2 deletions

View File

@ -46,7 +46,7 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
(_file, _file))
return
# Check if the source, _file, is a child folder within destination
elif destination.startswith(os.path.dirname(_file)):
elif destination.startswith(os.path.abspath(os.path.dirname(_file))+os.sep):
print('{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}' % (_file, destination))
return

View File

@ -240,6 +240,22 @@ def test_import_destination_in_source():
folder_destination = '{}/destination'.format(folder)
os.mkdir(folder_destination)
origin = '%s/plain.jpg' % folder
shutil.copyfile(helper.get_file('plain.jpg'), origin)
helper.reset_dbs()
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
helper.restore_dbs()
shutil.rmtree(folder)
assert dest_path is None, dest_path
def test_import_destination_in_source_gh_287():
temporary_folder, folder = helper.create_working_folder()
folder_destination = '{}-destination'.format(folder)
os.mkdir(folder_destination)
origin = '%s/video.mov' % folder
shutil.copyfile(helper.get_file('video.mov'), origin)
@ -249,7 +265,7 @@ def test_import_destination_in_source():
shutil.rmtree(folder)
assert dest_path is None, dest_path
assert dest_path is not None, dest_path
def test_import_invalid_file_exit_code():
temporary_folder, folder = helper.create_working_folder()