Currently, if /work does not exist, we go into the exception handler which
doesn't do anything if the errno is ENOENT, even though we still need to
remove the parent directory.
# the subdirectory when it is empty is not a problem because deleting a subdirectory depends on the
# permissions of the parent directory and not the directory itself.
try:
- (d / "work").rmdir()
+ if (p := d / "work").exists():
+ p.rmdir()
except OSError as e:
if e.errno == errno.ENOTEMPTY:
shutil.rmtree(d)
fork_and_wait(remove)
- elif e.errno != errno.ENOENT:
+ else:
raise
else:
shutil.rmtree(d)