From 5aa1bf91884613312abfd2faac3f5d57beca4a9c Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Tue, 5 Dec 2017 11:43:50 -0800 Subject: [PATCH] Also clean renamed-to files by unsetting the rename bit Signed-off-by: Matthew Johnson --- src/manifest.c | 14 +++++++++----- test/functional/orphaned-renames/test.bats | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/manifest.c b/src/manifest.c index e481c21..0c487b9 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -1037,12 +1037,16 @@ void clean_renames(struct manifest *manifest) list = g_list_first(manifest->files); while (list) { file = list->data; - /* if the file is marked as deleted and renamed it is a - * renamed-from file. If the rename_peer field is still NULL - * then it has been orphaned. Mark these as deleted */ - if (file->is_deleted && file->is_rename && !file->rename_peer) { - hash_set_zeros(file->hash); + /* if a file is marked as a rename but has lost its rename_peer + * it needs to be cleaned up */ + if (file->is_rename && !file->rename_peer) { + /* no longer a rename */ file->is_rename = 0; + /* if the file is marked as deleted and renamed it is a + * renamed-from file. Mark these as deleted now */ + if (file->is_deleted) { + hash_set_zeros(file->hash); + } } list = g_list_next(list); diff --git a/test/functional/orphaned-renames/test.bats b/test/functional/orphaned-renames/test.bats index a9beec9..b50ad41 100755 --- a/test/functional/orphaned-renames/test.bats +++ b/test/functional/orphaned-renames/test.bats @@ -34,15 +34,19 @@ setup() { # /usr/lib/bar and /one will be renamed to /usr/lib/baz and /two gen_file_plain_with_content 10 test-bundle /usr/lib/bar "$(seq 100)" gen_file_plain_with_content 10 test-bundle /one "$(printf 'a%.0s' {1..200})" + gen_file_plain_with_content 10 test-bundle /usr/lib/kernel/a "$(printf 'a%.0s' {1..210})" gen_file_plain_with_content 20 test-bundle /usr/lib/baz "$(seq 100)" gen_file_plain_with_content 20 test-bundle /two "$(printf 'a%.0s' {1..200})" + gen_file_plain_with_content 20 test-bundle /usr/lib/kernel/ab "$(printf 'a%.0s' {1..210})" # different content just to make sure this works with delta renames as well as # direct renames gen_file_plain_with_content 30 test-bundle /usr/lib/foo "$(seq 100) new" + gen_file_plain_with_content 30 test-bundle /usr/lib/kernel/abc "$(printf 'a%.0s' {1..210})" gen_file_plain_with_content 40 test-bundle /usr/lib/foo "$(seq 100) new" + gen_file_plain_with_content 40 test-bundle /usr/lib/kernel/abc "$(printf 'a%.0s' {1..210})" # new file to force manifest generation gen_file_plain_with_content 40 test-bundle /a "testfile" } @@ -68,11 +72,14 @@ setup() { # version 10: add files to 10 [ 1 -eq $(grep $'F\.\.\.\t.*\t10\t/usr/lib/bar' $DIR/www/10/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'F\.\.\.\t.*\t10\t/one' $DIR/www/10/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'F\.b\.\t.*\t10\t/usr/lib/kernel/a' $DIR/www/10/Manifest.test-bundle | wc -l) ] # version 20: rename bar to baz and one to two [ 1 -eq $(grep $'\.d\.r\t.*\t20\t/one' $DIR/www/20/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'F\.\.r\t.*\t20\t/two' $DIR/www/20/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'\.d\.r\t.*\t20\t/usr/lib/bar' $DIR/www/20/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'F\.\.r\t.*\t20\t/usr/lib/baz' $DIR/www/20/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'\.gbr\t.*\t20\t/usr/lib/kernel/a' $DIR/www/20/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'F\.br\t.*\t20\t/usr/lib/kernel/ab' $DIR/www/20/Manifest.test-bundle | wc -l) ] # version 30: original renamed-from file (bar) is now orphaned and therefore # deleted, baz is now a renamed-from file and foo is a renamed-to file. # /two was deleted in this version, so both /one and /two should be marked as @@ -82,6 +89,8 @@ setup() { [ 1 -eq $(grep $'\.d\.\.\t0\{64\}\t20\t/usr/lib/bar' $DIR/www/30/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'\.d\.r\t.*\t30\t/usr/lib/baz' $DIR/www/30/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'F\.\.r\t.*\t30\t/usr/lib/foo' $DIR/www/30/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'\.gbr\t.*\t30\t/usr/lib/kernel/ab' $DIR/www/30/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'F\.br\t.*\t30\t/usr/lib/kernel/abc' $DIR/www/30/Manifest.test-bundle | wc -l) ] # version 40: the existing rename from baz -> foo must persist while all # others remain deleted @@ -90,6 +99,7 @@ setup() { [ 1 -eq $(grep $'\.d\.\.\t0\{64\}\t20\t/usr/lib/bar' $DIR/www/40/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'\.d\.r\t.*\t30\t/usr/lib/baz' $DIR/www/40/Manifest.test-bundle | wc -l) ] [ 1 -eq $(grep $'F\.\.r\t.*\t30\t/usr/lib/foo' $DIR/www/40/Manifest.test-bundle | wc -l) ] + [ 1 -eq $(grep $'F\.b\.\t.*\t30\t/usr/lib/kernel/abc' $DIR/www/40/Manifest.test-bundle | wc -l) ] } # vi: ft=sh ts=8 sw=2 sts=2 et tw=80