2727ROLLBACK_ACTIONS = "delete_dir" , "delete_file" , "replace_file"
2828
2929
30+ # TODO: allow disabling rollbacks entirely
31+
3032class Transaction :
3133 """
3234 A filesystem transaction.
@@ -79,12 +81,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
7981 for line in rollback_txt .split ("\n " )
8082 ] if record ]
8183
82- for record in rollback_records :
83- logger .debug (f"Running rollback { record } " )
84- action = record [0 ]
85- args = record [1 :]
86- action_method = getattr (self , "_" + action )
87- action_method (* args )
84+ if rollback_records :
85+ logger .info (f"Rolling back { len (rollback_records )} action(s)" )
86+ for record in rollback_records :
87+ logger .debug (f"Running rollback { record } " )
88+ action = record [0 ]
89+ args = record [1 :]
90+ action_method = getattr (self , "_" + action )
91+ action_method (* args )
8892
8993 self ._rollback_dir .delete (recursive = True )
9094
@@ -96,15 +100,17 @@ def __exit__(self, exc_type, exc_val, exc_tb):
96100 logger .warning ("Note, it should be save to delete it manually." )
97101
98102 def _delete_dir (self , target_path ):
99- self ._target_dir .fs .rm (target_path , recursive = True )
103+ _dir = self ._target_dir / target_path
104+ _dir .delete (recursive = True )
100105
101106 def _delete_file (self , target_path ):
102- self ._target_dir .fs .rm (target_path )
107+ _file = self ._target_dir / target_path
108+ _file .delete ()
103109
104110 def _replace_file (self , target_path , rollback_filename ):
111+ _file = self ._target_dir / target_path
105112 data = (self ._rollback_dir / rollback_filename ).read ()
106- with self ._target_dir .fs .open (target_path , "wb" ) as f :
107- f .write (data )
113+ _file .write (data )
108114
109115 def _add_rollback_action (self ,
110116 action : RollbackAction ,
0 commit comments