diff --git a/elodie.py b/elodie.py index e0fd37b..2f54fa3 100755 --- a/elodie.py +++ b/elodie.py @@ -40,6 +40,11 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates): print('{"source":"%s", "error_msg":"Could not find %s"}' % \ (_file, _file)) return + # Check if the source, _file, is a child folder within destination + elif destination.startswith(os.path.dirname(_file)): + print('{"source": "%s", "destination": "%s", "error_msg": "Cannot be in destination"}' % (_file, destination)) + return + media = Media.get_class_by_file(_file, [Text, Audio, Photo, Video]) if not media: @@ -78,7 +83,7 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates): def _import(destination, source, file, album_from_folder, trash, paths, allow_duplicates): """Import files or directories by reading their EXIF and organizing them accordingly. """ - destination = os.path.expanduser(destination) + destination = os.path.abspath(os.path.expanduser(destination)) files = set() paths = set(paths) diff --git a/elodie/tests/elodie_test.py b/elodie/tests/elodie_test.py index f5c57ea..27635f1 100644 --- a/elodie/tests/elodie_test.py +++ b/elodie/tests/elodie_test.py @@ -122,6 +122,22 @@ def test_import_file_allow_duplicate_true(): assert dest_path2 is not None assert dest_path1 == dest_path2 +def test_import_destination_in_source(): + 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) + + reset_hash_db() + dest_path = elodie.import_file(origin, folder_destination, False, False, False) + restore_hash_db() + + shutil.rmtree(folder) + + assert dest_path is None, dest_path + def test_update_location_on_audio(): temporary_folder, folder = helper.create_working_folder() temporary_folder_destination, folder_destination = helper.create_working_folder()