diff --git a/elodie.py b/elodie.py index 16d0705..54c69ee 100755 --- a/elodie.py +++ b/elodie.py @@ -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 diff --git a/elodie/tests/elodie_test.py b/elodie/tests/elodie_test.py index 884d55a..c05a8c8 100644 --- a/elodie/tests/elodie_test.py +++ b/elodie/tests/elodie_test.py @@ -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()