* [PATCH] gentree: keep directory intact and ignore if missing
@ 2026-05-08 7:02 Yi Cong
0 siblings, 0 replies; only message in thread
From: Yi Cong @ 2026-05-08 7:02 UTC (permalink / raw)
To: hauke, backports; +Cc: yicong
From: Yi Cong <yicong@kylinos.cn>
Previously, `shutil.rmtree` removed the target directory
itself, breaking active terminal sessions in target output
and then need to cd target directory again which add some
additional operations during the manual debug test.
Optimize it so that only the output directory is cleared,
rather than deleting the entire thing.
Signed-off-by: Yi Cong <yicong@kylinos.cn>
---
gentree.py | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/gentree.py b/gentree.py
index d709b907..7940c145 100755
--- a/gentree.py
+++ b/gentree.py
@@ -119,13 +119,22 @@ def check_output_dir(d, clean):
sanity check the output when generating a tree, so usually
running with --clean isn't suggested.
"""
+ if not os.path.exists(d):
+ return
+
if clean:
- shutil.rmtree(d, ignore_errors=True)
- try:
- os.rmdir(d)
- except OSError as e:
- if e.errno != errno.ENOENT:
- raise
+ for item in os.listdir(d):
+ item_path = os.path.join(d, item)
+ if os.path.isdir(item_path) and not os.path.islink(item_path):
+ shutil.rmtree(item_path)
+ else:
+ os.unlink(item_path)
+ else:
+ if os.listdir(d):
+ raise OSError(
+ "Output directory '{}' exists and is not empty. "
+ "Use --clean to overwrite.".format(d)
+ )
def copytree(src, dst, symlinks=False, ignore=None):
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-08 7:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 7:02 [PATCH] gentree: keep directory intact and ignore if missing Yi Cong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.