From 9519488b3a7c3146a093b6e50d77df4be23775a7 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sat, 19 Oct 2024 01:44:24 +0000 Subject: [PATCH] project: "fail fast" west init when directories cannot be renamed In October 2024, a problem reported in #558 showed that some Windows systems can be configured to allow directory and file creations but not renames. Test this _before_ git cloning to "fail fast" and remove git from the very confusing picture. Signed-off-by: Marc Herbert --- src/west/app/project.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index 33bd95dc..cc918719 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -307,11 +307,28 @@ def bootstrap(self, args) -> Path: if not topdir.is_dir(): self.create(topdir, exist_ok=False) - # Clone the manifest repository into a temporary directory. tempdir: Path = west_dir / 'manifest-tmp' if tempdir.is_dir(): self.dbg('removing existing temporary manifest directory', tempdir) shutil.rmtree(tempdir) + + # Test that we can rename and delete directories. For the vast + # majority of users this is a no-op but some filesystem + # permissions can be weird; see October 2024 example in west + # issue #558. Git cloning can take a long time, so check this + # first. Failing ourselves is not just faster, it's also much + # clearer than when git is involved in the mix. + + tempdir.mkdir(parents=True) + (tempdir / 'not empty').mkdir() + # Ignore the --rename-delay hack here not to double the wait; + # we only have a couple directories and no file at this point! + tempdir2 = tempdir.parent / 'renamed tempdir' + os.rename(tempdir, tempdir2) + # No need to delete west_dir parent + shutil.rmtree(tempdir2) + + # Clone the manifest repository into a temporary directory. try: self.small_banner( f'Cloning manifest repository from {manifest_url}' +