From 010131eb85b7b6a86b9febcdb6ce1891e05c8ad7 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Tue, 28 Nov 2017 13:19:06 -0800 Subject: [PATCH] Fix ghosted-file deprecation Ghosted files were only being deprecated over format bumps. Move the format-bump-check logic out to the calling function to allow ghosted files to be removed on every build. Also assign the is_ghosted flag when adding "deleted" files from the old manifest so that the file will actually be removed. Signed-off-by: Matthew Johnson --- src/create_update.c | 21 ++++++++++++++++++--- src/manifest.c | 17 +++++++---------- test/functional/ghosting/test.bats | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/create_update.c b/src/create_update.c index f514d43..c05420d 100644 --- a/src/create_update.c +++ b/src/create_update.c @@ -336,7 +336,12 @@ int main(int argc, char **argv) apply_heuristics(new_full); match_manifests(old_full, new_full); - old_deleted = remove_deprecated_files(old_full, new_full, both_deleted); + if (old_full->format < new_full->format) { + old_deleted = remove_deprecated_files(old_full, new_full, both_deleted); + } else { + old_deleted = 0; + } + if (old_deleted > 0) { LOG(NULL, "", "Old deleted files (%d) removed from full manifest", old_deleted); printf("Old deleted files (%d) removed from full manifest\n", old_deleted); @@ -402,7 +407,12 @@ int main(int argc, char **argv) /* Detect renamed files specifically for os-core */ rename_detection(new_core); #endif - old_deleted = remove_deprecated_files(old_core, new_core, both_deleted); + if (old_core->format < new_core->format) { + old_deleted = remove_deprecated_files(old_core, new_core, both_deleted); + } else { + old_deleted = 0; + } + old_ghosted = remove_deprecated_files(old_core, new_core, both_ghosted); sort_manifest_by_version(new_core); /* sorts by filename */ /* clean up orphaned renames by marking them as deleted */ @@ -526,7 +536,12 @@ int main(int argc, char **argv) rename_detection(newm); #endif /* Step 6b: otherwise, write out the manifest */ - old_deleted = remove_deprecated_files(oldm, newm, both_deleted); + if (oldm->format < newm->format) { + old_deleted = remove_deprecated_files(oldm, newm, both_deleted); + } else { + old_deleted = 0; + } + old_ghosted = remove_deprecated_files(oldm, newm, both_ghosted); sort_manifest_by_version(newm); type_change_detection(newm); diff --git a/src/manifest.c b/src/manifest.c index ea3fea5..45ea3e0 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -440,8 +440,11 @@ int match_manifests(struct manifest *m1, struct manifest *m2) file3->is_config = file1->is_config; file3->is_state = file1->is_state; file3->is_boot = file1->is_boot; + file3->is_ghosted = file1->is_ghosted; /* ghost deleted boot files */ - file3->is_ghosted = file1->is_boot && file1->is_deleted; + if (!file3->is_ghosted) { + file3->is_ghosted = file1->is_boot && file1->is_deleted; + } if (file3->is_ghosted || file1->is_deleted) { /* if the new file is ghosted or the file was deleted, preserve @@ -983,10 +986,9 @@ bool changed_includes(struct manifest *old, struct manifest *new) return false; } -/* For a format bump, it's convenient to remove deleted files from manifests - * that last changed prior to the format bump, since they are no longer - * considered for deletion as part of an update. - * +/* Remove files deprecated in this version as identified by the compfunc + * function. This function can be used to remove old deleted files over a format + * bump and remove deprecated ghosted files. * Note: this function should be called after match_manifests(). */ int remove_deprecated_files(struct manifest *m1, struct manifest *m2, bool (*compfunc)(struct file *file1, struct file *file2)) @@ -1005,11 +1007,6 @@ int remove_deprecated_files(struct manifest *m1, struct manifest *m2, bool (*com return -1; } - /* This is the common case, so bail early, reporting no deletions */ - if (m1->format == m2->format) { - return 0; - } - /* At this point, the manifest formats mismatch, and it's assumed that * m1 is the old manifest, and m2 is the new. */ diff --git a/test/functional/ghosting/test.bats b/test/functional/ghosting/test.bats index 6b44a96..9d5c6b8 100755 --- a/test/functional/ghosting/test.bats +++ b/test/functional/ghosting/test.bats @@ -52,7 +52,7 @@ setup() { # version 20: add a new boot file [ 1 -eq $(grep 'F\.b\. .* 20 /usr/lib/kernel/baz' $DIR/www/20/Manifest.full | wc -l) ] # version 30: old ghosted file /usr/lib/kernel/bar cleaned up - [ 0 -eq $(grep '10 /usr/lib/kernel/bar' $DIR/www/30/Manifest.full | wc -l) ] + [ 0 -eq $(grep '/usr/lib/kernel/bar' $DIR/www/30/Manifest.full | wc -l) ] # version 30: boot file added in version 20 ghosted [ 1 -eq $(grep '\.gb\. .* 30 /usr/lib/kernel/baz' $DIR/www/30/Manifest.full | wc -l) ] }