lib/repo: Auto-recreate repo/tmp if it's deleted

We can accumulate a lot of space there; let's be nice to people who delete the
whole directory.

Closes: https://github.com/ostreedev/ostree/issues/1018

Closes: #1020
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-07-19 10:35:06 -04:00 committed by Atomic Bot
parent c740b7f6d2
commit 779f125cbe
2 changed files with 23 additions and 1 deletions

View File

@ -2201,6 +2201,20 @@ ostree_repo_open (OstreeRepo *self,
self->target_owner_uid = self->target_owner_gid = -1; self->target_owner_uid = self->target_owner_gid = -1;
} }
if (self->writable)
{
/* Always try to recreate the tmpdir to be nice to people
* who are looking to free up space.
*
* https://github.com/ostreedev/ostree/issues/1018
*/
if (mkdirat (self->repo_dir_fd, "tmp", 0755) == -1)
{
if (G_UNLIKELY (errno != EEXIST))
return glnx_throw_errno_prefix (error, "mkdir(tmp)");
}
}
if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error)) if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error))
return FALSE; return FALSE;

View File

@ -19,7 +19,7 @@
set -euo pipefail set -euo pipefail
echo "1..$((69 + ${extra_basic_tests:-0}))" echo "1..$((70 + ${extra_basic_tests:-0}))"
$CMD_PREFIX ostree --version > version.yaml $CMD_PREFIX ostree --version > version.yaml
python -c 'import yaml; yaml.safe_load(open("version.yaml"))' python -c 'import yaml; yaml.safe_load(open("version.yaml"))'
@ -112,6 +112,14 @@ ostree_repo_init test-repo --mode=bare-user
rm test-repo -rf rm test-repo -rf
echo "ok repo-init on existing repo" echo "ok repo-init on existing repo"
rm test-repo -rf
ostree_repo_init test-repo --mode=bare-user
${CMD_PREFIX} ostree --repo=test-repo refs
rm -rf test-repo/tmp
${CMD_PREFIX} ostree --repo=test-repo refs
assert_has_dir test-repo/tmp
echo "ok autocreate tmp"
rm checkout-test2 -rf rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2 $OSTREE checkout test2 checkout-test2
cd checkout-test2 cd checkout-test2