package/python3: use depth first search for directory removal

Previously, Python builds could intermittently fail when removing files
if `find` removed a directory before searching within it [0].

An arbitrary example:

  /tmp/tmp.h9KMUse5zO $ find . -type d -name __pycache__ -exec rm -rvf {} \; ; echo -e "RETURN CODE: $?"
  removed directory './a/b/c/d/e/__pycache__'
  find: ‘./a/b/c/d/e/__pycache__’: No such file or directory
  removed directory './a/b/c/d/e/f/__pycache__'
  find: ‘./a/b/c/d/e/f/__pycache__’: No such file or directory
  removed directory './a/b/c/d/e/f/g/__pycache__'
  RETURN CODE: 1

Now, pass the `-depth` argument to `find` so a depth-first search is
performed to avoid trying to search within an already deleted folder.

Fixes: 54d48c8cad ("package/python3: miscellaneous fixups")
Fixes: http://autobuild.buildroot.net/results/ba1d4213ae9912d53412ded6d8e257b67a4f7c0e/
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Vincent Fazio
2024-07-16 23:28:44 +02:00
committed by Thomas Petazzoni
parent 531fc0a60e
commit ec531a271b
+2 -2
View File
@@ -205,8 +205,8 @@ define PYTHON3_REMOVE_USELESS_FILES
rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
rm -f $(TARGET_DIR)/usr/bin/python3-config
find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)*/ \
-type f -not -name Makefile -exec rm -rf {} \;
find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/ -type d \
-depth -type f -not -name Makefile -exec rm -rf {} \;
find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/ -depth -type d \
-name __pycache__ -exec rm -rf {} \;
endef