Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Also clean renamed-to files by unsetting the rename bit
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
  • Loading branch information
matthewrsj committed Dec 5, 2017
1 parent de04b84 commit 5aa1bf9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test/functional/orphaned-renames/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 5aa1bf9

Please sign in to comment.