File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -299,23 +299,21 @@ def _relocate(src, dst):
299
299
if src == dst :
300
300
return
301
301
302
- _action = action
302
+ # If the source is not contained in source_directories we're not allowed to delete it
303
+ src_can_deleted = any (os .path .commonprefix ([p , src ]) == p for p in source_directories )
304
+
305
+ _action = "move" if action == "move" and src_can_deleted else "copy"
306
+
303
307
if _action == "move" :
304
- # do not move anything if we are trying to move an entity from
305
- # outside of the source directories
306
- if any (os .path .commonprefix ([path , src ]) == path for path in source_directories ):
307
- _logger .debug ("Moving %s to %s" , src , dst )
308
- if fs_access .isdir (src ) and fs_access .isdir (dst ):
309
- # merge directories
310
- for dir_entry in scandir (src ):
311
- _relocate (dir_entry .path , fs_access .join (dst , dir_entry .name ))
312
- else :
313
- shutil .move (src , dst )
308
+ _logger .debug ("Moving %s to %s" , src , dst )
309
+ if fs_access .isdir (src ) and fs_access .isdir (dst ):
310
+ # merge directories
311
+ for dir_entry in scandir (src ):
312
+ _relocate (dir_entry .path , fs_access .join (dst , dir_entry .name ))
314
313
else :
315
- # we still need the files at the destination, so let's copy them
316
- _action = "copy"
314
+ shutil .move (src , dst )
317
315
318
- if _action == "copy" :
316
+ elif _action == "copy" :
319
317
_logger .debug ("Copying %s to %s" , src , dst )
320
318
if fs_access .isdir (src ):
321
319
if os .path .isdir (dst ):
You can’t perform that action at this time.
0 commit comments