def remove(path, dest_root, dryrun=False, debug=False):
"""
Remove the specified file/directory using `rm -rf`, to clean
up the destination backup.
The specified path must locate under the `dest_root` for safety.
"""
if not fnmatch(path, dest_root+"/*"):
raise ValueError("Not allowed to remove file/directory "
"outside destination: %s" % path)
if not os.path.exists(path):
return
logger.info("Remove: %s" % path)
args = ["-r", "-f"]
if debug:
args += ["-v"]
cmd = ["rm"] + args + [path]
if not dryrun:
subprocess.check_call(cmd)
评论列表
文章目录