briefcase: Incomplete deletion of old project not correctly idenfied

Originally reported as a side effect of #300

If you have previously run briefcase create for a given app, you’ll be warned, and prompted to delete the old app:

(beeware-venv) lov080@DARKZERO-LN helloworld % briefcase create iOS            

Application helloworld already exists; overwrite (y/N)? y

Briefcase currently assumes that the app deletion is complete.

However, if something prevents the app from being deleted (e.g., an open terminal session, or the app being currently open, you will get an error:

[helloworld] Removing old application bundle...
Traceback (most recent call last):
  File "/Users/lov080/Google Drive/Python/BeeWare/examples/beeware-tutorial/beeware-venv/bin/briefcase", line 12, in <module>
    sys.exit(main())
  File "/Users/lov080/Google Drive/Python/BeeWare/examples/beeware-tutorial/beeware-venv/lib/python3.8/site-packages/briefcase/__main__.py", line 11, in main
    command(**options)
  File "/Users/lov080/Google Drive/Python/BeeWare/examples/beeware-tutorial/beeware-venv/lib/python3.8/site-packages/briefcase/commands/create.py", line 610, in __call__
    state = self.create_app(app, **full_kwargs(state, kwargs))
  File "/Users/lov080/Google Drive/Python/BeeWare/examples/beeware-tutorial/beeware-venv/lib/python3.8/site-packages/briefcase/commands/create.py", line 564, in create_app
    self.shutil.rmtree(str(bundle_path))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 730, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 612, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 610, in _rmtree_unsafe
    os.rmdir(path)
OSError: [Errno 66] Directory not empty: '/Users/lov080/Google Drive/Python/BeeWare/examples/beeware-tutorial/helloworld/iOS/Hello World'

but the create command will continue, resulting in a state where the app hasn’t been recreated.

This edge case needs to be caught and corrected - we should check that the deletion completed without error before creating the new app.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (12 by maintainers)

Most upvoted comments

OK, if you can post some logs (generated by briefcase --log) proving that the behavior is now correct on Linux and Windows, then someone else can check on macOS and we can close this issue.

The original bug wasn’t about how the exception is reported, but that “but the create command will continue”. The command should not continue.

It’s probably most likely to happen on Windows, where you can’t delete a file which a process has open. The Android Gradle daemon has a tendency to cause this situation.

But if the original bug of ignoring the exception still exists, you should be able to reproduce it on any platform with any target, simply by changing one of the build subdirectories to be non-writable.

@proneon267 It’s possible this may be macOS specific. I know that having a terminal session open in Linux won’t prevent a directory being deleted. I’m not sure if there might be other conditions that could prevent a directory from being deleted (other than a direct permissions change, which shouldn’t happen in the case of Briefcase, but could happen if someone gets creative in their build folder). I don’t have enough experience with Windows to say for certain if the same problem could exist.