File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,24 @@ def finished(self) -> bool:
5050 return self ._finished
5151
5252 def create (self ) -> Path :
53- """Create the COW upper directory."""
53+ """Create the COW upper directory.
54+
55+ Also cleans up any orphaned storage dirs from killed processes.
56+ """
57+ # Clean stale dirs from previous crashed runs
58+ if self ._storage .exists ():
59+ for entry in self ._storage .iterdir ():
60+ if entry .is_dir ():
61+ try :
62+ # Check if the owning process is still alive
63+ # Storage parent is /tmp/sandlock-cow-<pid>
64+ parts = self ._storage .name .split ("-" )
65+ if len (parts ) >= 3 and parts [- 1 ].isdigit ():
66+ pid = int (parts [- 1 ])
67+ os .kill (pid , 0 ) # check if alive
68+ except (ProcessLookupError , ValueError ):
69+ shutil .rmtree (str (entry ), ignore_errors = True )
70+
5471 self ._branch_id = uuid .uuid4 ().hex [:12 ]
5572 branch_dir = self ._storage / self ._branch_id
5673 branch_dir .mkdir (parents = True , exist_ok = True )
You can’t perform that action at this time.
0 commit comments