gh-145 Check if destination is in source and skip import
This commit is contained in:
parent
7edcfed421
commit
92c3818720
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue