Skip to content

Commit 4edb1e0

Browse files
committed
cleanup destination if move fails
1 parent fd577df commit 4edb1e0

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

fs/move.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from . import open_fs
1111
from .copy import copy_dir
1212
from .copy import copy_file
13-
from .errors import ResourceReadOnly
13+
from .errors import FSError, ResourceReadOnly
1414
from .opener import manage_fs
1515
from .path import frombase
1616

@@ -103,7 +103,13 @@ def move_file(
103103
dst_path,
104104
preserve_time=preserve_time,
105105
)
106-
_src_fs.remove(src_path)
106+
try:
107+
_src_fs.remove(src_path)
108+
except FSError as e:
109+
# if the source cannot be removed we delete the copy on the
110+
# destination
111+
_dst_fs.remove(dst_path)
112+
raise e
107113

108114

109115
def move_dir(

0 commit comments

Comments
 (0)