Skip to content

Commit

Permalink
west manifest: detect when target directory already exists, and fail
Browse files Browse the repository at this point in the history
When setting up a project with west, the target directory may not be
initialized correctly. In the typical case, if a directory named
`./zephyr/` already exists, the user may find that checkout files are
located at `./zephyr/manifest-tmp/*` instead of the expected
`./zephyr/*`.

This patch will abort and refuse to complete `west init` if the
destination directory alread exists. This check would ideally occur
before the potentially lengthy clone operation, but `manifest_path` is
derived from the files retrieved...

NOTE: If the project quotes a value other than `zephyr` for
`manifest.self.path` in `/west.yml`, then this will affect that
directory instead.

Steps to reproduce before this patch:

  mkdir ./zephyr/
  west init ./ -m https://github.com/zephyrproject-rtos/zephyr.git
  ls -l ./zephyr/

Signed-off-by: Attie Grande <[email protected]>
  • Loading branch information
attie-argentum committed Aug 28, 2023
1 parent 9e8f500 commit d8f2e5e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ def bootstrap(self, args) -> Path:

manifest_abspath = topdir / manifest_path

# As shutil.move() is used to relocate tempdir, if manifest_abspath
# is an existing directory, tmpdir will be moved _inside_ it, instead
# of _to_ that path - this must be avoided. If manifest_abspath exists
# but is not a directory, then semantics depend on os.rename(), so
# avoid that too...
if manifest_abspath.exists():
self.die(f'target directory already exists ({manifest_abspath})')

self.dbg('moving', tempdir, 'to', manifest_abspath,
level=Verbosity.DBG_EXTREME)
manifest_abspath.parent.mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit d8f2e5e

Please sign in to comment.