Allow overwrite of directories in copy_to_dist_dir
If we would like to run _dist tasks twice, we have to allow overwriting
files inside directories. It is enough to make directory writable before
copying its contents, which allows removal of the files inside. Then
shutil.copytree will restore correct permissions through the copystat.
Test: TH
Bug: 267607344
Change-Id: I11f8e330c06d71ef1a1b674f846f70bd1bbb1931
diff --git a/dist/dist.py b/dist/dist.py
index 4579a11..c9f7be9 100644
--- a/dist/dist.py
+++ b/dist/dist.py
@@ -122,6 +122,10 @@
copy_with_modes(src, dst, mode_overrides)
elif os.path.isdir(src):
logging.debug("Copying dir: %s" % dst)
+ if os.path.exists(dst):
+ # make the directory temporary writable, then
+ # shutil.copytree will restore correct permissions.
+ os.chmod(dst, 750)
shutil.copytree(
os.path.abspath(src),
dst,