Skip to content

Commit

Permalink
project: "fail fast" west init when directories cannot be renamed
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
marc-hb committed Oct 19, 2024
1 parent 88affcc commit e83ac48
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --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}' +
Expand Down

0 comments on commit e83ac48

Please sign in to comment.