예제 #1
0
파일: fsops.py 프로젝트: Byron/bcore
class DeleteOperation(Operation):

    """Delete a file or a directory. Please note that, for obvious reasons, failures
    cannot be undone. This operation will stop at the first encountered error"""

    __slots__ = "_path"     # the path to delete
    name = "DeleteOperation"

    def __init__(self, transaction, path):
        super(DeleteOperation, self).__init__(transaction)
        self._path = Path(path)

    def apply(self):
        if self._dry_run():
            return

        if self._path.isdir():
            self.log.info("Deleting directory %s", self._path)
            self._path.rmtree()
        else:
            self.log.info("Deleting file %s", self._path)
            self._path.remove()
        # END perform actual removal

    def rollback(self):
        self.log.info("Deletion of filesystem items cannot be rolled back")