Improve rb-site's method of checking the site directory on install.

Review Request #11443 — Created Feb. 11, 2021 and submitted — Latest diff uploaded

Information

Review Board
release-3.0.x

Reviewers

Before walking a user through the installation process, rb-site checks
to make sure the directory can be written to and that it's free of
files. The way it would historically do this would be to try to remove
the directory, since installation would re-create it. However, this
approach isn't particularly great, for a few reasons:

1) It might have been pre-created with proper ownership, which the
removal would undo.

2) If that directory was a mounted filesystem, it couldn't just remove
it.

3) When things went wrong, our error message just had to guess at the
cause.

This change redoes the logic, explicitly checking first if the path
exists. If it does, it checks for existing files, and bails with a
helpful error if it finds any. If no files exist, it tries to write a
temporary file to it to check permissions.

If the path does not exist, it then tries to create and then remove it,
checking permissions on the parent directory.

This is far safer, and gives more flexibility when running in a Docker
image or installing to a top-level NFS mount.

Successfully installed in a brand-new directory.

Successfully installed in an empty directory.

Tried installing in a directory with files, and saw a suitable error.

Tried installing in an unwritable empty directory, and saw a suitable error.

Tried installing to a brand-new directory that couldn't be created, and saw
a suitable error.

Commits

Files