Include path separator and absolute path when checking if destination is a child of the source. Fixes gh-287
This commit is contained in:
		
							parent
							
								
									3f96e09126
								
							
						
					
					
						commit
						91bf181575
					
				| @ -46,7 +46,7 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates): | |||||||
|             (_file, _file)) |             (_file, _file)) | ||||||
|         return |         return | ||||||
|     # Check if the source, _file, is a child folder within destination |     # 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)) |         print('{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}' % (_file, destination)) | ||||||
|         return |         return | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -240,6 +240,22 @@ def test_import_destination_in_source(): | |||||||
|     folder_destination = '{}/destination'.format(folder) |     folder_destination = '{}/destination'.format(folder) | ||||||
|     os.mkdir(folder_destination) |     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 |     origin = '%s/video.mov' % folder | ||||||
|     shutil.copyfile(helper.get_file('video.mov'), origin) |     shutil.copyfile(helper.get_file('video.mov'), origin) | ||||||
| 
 | 
 | ||||||
| @ -249,7 +265,7 @@ def test_import_destination_in_source(): | |||||||
| 
 | 
 | ||||||
|     shutil.rmtree(folder) |     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(): | def test_import_invalid_file_exit_code(): | ||||||
|     temporary_folder, folder = helper.create_working_folder() |     temporary_folder, folder = helper.create_working_folder() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jaisen Mathai
						Jaisen Mathai