Skip to content

Commit

Permalink
fixup! Add support for more selective pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Jan 18, 2017
1 parent f6eb4c1 commit dbe1af9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libostree/libostree.sym
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ global:
* NOTE NOTE NOTE
*/

LIBOSTREE_2016.15 {
LIBOSTREE_2017.1 {
global:
ostree_repo_prune_from_reachable;
} LIBOSTREE_2016.14;
Expand Down
23 changes: 22 additions & 1 deletion src/ostree/ot-builtin-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
/* bd should look like BRANCH=DEPTH where DEPTH is an int */
const char *bd = *iter;
const char *eq = strchr (bd, '=');
const char *depthstr;
gint64 depth;
char *endptr;

if (!eq)
{
Expand All @@ -223,8 +226,26 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
bd);
goto out;
}
depthstr = eq + 1;
errno = EPERM;
depth = g_ascii_strtoll (depthstr, &endptr, 10);
if (depth == 0)
{
if (errno == EINVAL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Out of range depth %s", depthstr);
goto out;
}
else if (endptr == depthstr)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid depth %s", depthstr);
goto out;
}
}
g_hash_table_insert (retain_branch_depth, g_strndup (bd, eq - bd),
GINT_TO_POINTER ((int)g_ascii_strtoll (eq + 1, NULL, 10)));
GINT_TO_POINTER ((int)depth));
}

/* We start from the refs */
Expand Down
5 changes: 5 additions & 0 deletions tests/test-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ reinitialize_datesnap_repo() {
# This test prunes with both younger than as well as a full strong ref to the
# stable branch
reinitialize_datesnap_repo
# First, a quick test of invalid input
if ${CMD_PREFIX} ostree --repo=repo prune --keep-younger-than="1 week ago" --retain-branch-depth=stable=BACON 2>err.txt; then
assert_not_reached "BACON is a number?!"
fi
assert_file_has_content err.txt 'Invalid depth BACON'
${CMD_PREFIX} ostree --repo=repo prune --keep-younger-than="1 week ago" --retain-branch-depth=stable=-1
find repo/objects -name '*.commit' | wc -l > commitcount
assert_file_has_content commitcount "^11$"
Expand Down

0 comments on commit dbe1af9

Please sign in to comment.