|
1 | 1 | import binascii |
| 2 | +import errno |
2 | 3 | import hashlib |
3 | 4 | import os |
4 | 5 | import sys |
@@ -300,6 +301,28 @@ def _mkdir(a, *b): |
300 | 301 | do_filesystem_cp(state, src_path_joined, dest_path_joined, False, check_hash) |
301 | 302 |
|
302 | 303 |
|
| 304 | +def do_filesystem_recursive_rm(state, path, args): |
| 305 | + if state.transport.fs_isdir(path): |
| 306 | + for entry in state.transport.fs_listdir(path): |
| 307 | + do_filesystem_recursive_rm(state, _remote_path_join(path, entry.name), args) |
| 308 | + if path: |
| 309 | + try: |
| 310 | + state.transport.fs_rmdir(path) |
| 311 | + if args.verbose: |
| 312 | + print(f"removed directory: '{path}'") |
| 313 | + except OSError as e: |
| 314 | + if e.errno != errno.EINVAL: # not vfs mountpoint |
| 315 | + raise CommandError( |
| 316 | + f"rm -r: cannot remove :{path} {os.strerror(e.errno) if e.errno else ''}" |
| 317 | + ) from e |
| 318 | + if args.verbose: |
| 319 | + print(f"skipped: '{path}' (vfs mountpoint)") |
| 320 | + else: |
| 321 | + state.transport.fs_rmfile(path) |
| 322 | + if args.verbose: |
| 323 | + print(f"removed: '{path}'") |
| 324 | + |
| 325 | + |
303 | 326 | def do_filesystem(state, args): |
304 | 327 | state.ensure_raw_repl() |
305 | 328 | state.did_action() |
@@ -352,7 +375,10 @@ def do_filesystem(state, args): |
352 | 375 | elif command == "mkdir": |
353 | 376 | state.transport.fs_mkdir(path) |
354 | 377 | elif command == "rm": |
355 | | - state.transport.fs_rmfile(path) |
| 378 | + if args.recursive: |
| 379 | + do_filesystem_recursive_rm(state, path, args) |
| 380 | + else: |
| 381 | + state.transport.fs_rmfile(path) |
356 | 382 | elif command == "rmdir": |
357 | 383 | state.transport.fs_rmdir(path) |
358 | 384 | elif command == "touch": |
|
0 commit comments