mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-07 22:21:32 +00:00
Add verify --fix --picky functionality
This is the basic implementation for a "factory reset" type of command. It will take the functionality of verify --picky and act on the files found as verify --fix does with files found mismatching in the manifest. Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
This commit is contained in:
+1
-1
@@ -168,7 +168,7 @@ extern void increment_retries(int *retries, int *timeout);
|
||||
extern int main_update(void);
|
||||
extern int add_included_manifests(struct manifest *mom, int current, struct list **subs);
|
||||
extern int main_verify(int current_version);
|
||||
extern int walk_tree(struct manifest *, const char *);
|
||||
extern int walk_tree(struct manifest *, const char *, bool);
|
||||
|
||||
extern int get_latest_version(void);
|
||||
extern void read_versions(int *current_version, int *server_version, char *path_prefix);
|
||||
|
||||
+21
-5
@@ -95,10 +95,11 @@ static int bsearch_helper(const void *A, const void *B)
|
||||
}
|
||||
|
||||
/* expect the start to end in /usr and be the absolute path to the root */
|
||||
int walk_tree(struct manifest *manifest, const char *start)
|
||||
int walk_tree(struct manifest *manifest, const char *start, bool fix)
|
||||
{
|
||||
/* Walk the tree, */
|
||||
int rc;
|
||||
char *temp;
|
||||
path_prefix_len = strlen(path_prefix);
|
||||
/* Set up the directories to skip */
|
||||
for (size_t i = 0; i < sizeof(skip_dirs) / sizeof(skip_dirs[0]); i++) {
|
||||
@@ -131,8 +132,9 @@ int walk_tree(struct manifest *manifest, const char *start)
|
||||
found->in_manifest = true;
|
||||
}
|
||||
}
|
||||
/* list files/directories which are extra */
|
||||
for (int i = 0; i < nF; i++) {
|
||||
/* list files/directories which are extra.
|
||||
* This is reverse so that files are removed before their parent dirs */
|
||||
for (int i = nF - 1; i >= 0; i--) {
|
||||
int skip_len; /* Length of directory name we are skipping
|
||||
* could have used strlen(skip_dir), but speed! */
|
||||
if (!F[i].in_manifest) {
|
||||
@@ -148,9 +150,23 @@ int walk_tree(struct manifest *manifest, const char *start)
|
||||
if (F[i].dir) { /* Start of new dir to skip */
|
||||
skip_dir = F[i].filename;
|
||||
skip_len = strlen(skip_dir);
|
||||
printf("%s/\n", F[i].filename);
|
||||
if (fix) {
|
||||
string_or_die(&temp, "%s%s", path_prefix, F[i].filename);
|
||||
fprintf(stderr, "REMOVING DIR %s/\n", F[i].filename);
|
||||
remove(temp);
|
||||
free(temp);
|
||||
} else {
|
||||
printf("%s/\n", F[i].filename);
|
||||
}
|
||||
} else {
|
||||
printf("%s\n", F[i].filename);
|
||||
if (fix) {
|
||||
string_or_die(&temp, "%s%s", path_prefix, F[i].filename);
|
||||
fprintf(stderr, "REMOVING %s\n", F[i].filename);
|
||||
remove(temp);
|
||||
free(temp);
|
||||
} else {
|
||||
printf("%s\n", F[i].filename);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skip_dir = NULL;
|
||||
|
||||
+11
-1
@@ -774,11 +774,21 @@ load_submanifests:
|
||||
if ((file_not_fixed_count == 0) && (file_not_replaced_count == 0)) {
|
||||
remove_orphaned_files(official_manifest);
|
||||
}
|
||||
if (cmdline_option_picky) {
|
||||
char *start = mk_full_filename(path_prefix, "/usr");
|
||||
fprintf(stderr, "--picky removing extra files under %s\n", start);
|
||||
ret = walk_tree(official_manifest, start, true);
|
||||
if (ret >= 0) {
|
||||
file_checked_count = ret;
|
||||
ret = 0;
|
||||
}
|
||||
free(start);
|
||||
}
|
||||
grabtime_stop(×);
|
||||
} else if (cmdline_option_picky) {
|
||||
char *start = mk_full_filename(path_prefix, "/usr");
|
||||
fprintf(stderr, "Generating list of extra files under %s\n", start);
|
||||
ret = walk_tree(official_manifest, start);
|
||||
ret = walk_tree(official_manifest, start, false);
|
||||
if (ret >= 0) {
|
||||
file_checked_count = ret;
|
||||
ret = 0;
|
||||
|
||||
Reference in New Issue
Block a user