Skip to content

Commit

Permalink
update: do not retry when server manifest not found
Browse files Browse the repository at this point in the history
Change load_mom to have a variant that can propagate the error code,
and check for that. Use that variant when downloading the
server_manifest. This approach could later be applied to other retries
that involve downloading.

With this patch, "update -m" to a non-published version will not retry
many times before failing.
  • Loading branch information
cmarcelo authored and matthewrsj committed Apr 15, 2018
1 parent c946930 commit c2f3537
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ void remove_manifest_files(char *filename, int version, char *hash)
}
}

struct manifest *load_mom(int version, bool latest, bool mix_exists)
{
return load_mom_err(version, latest, mix_exists, NULL);
}

/* Loads the MoM (Manifest of Manifests) for VERSION.
*
* Implementation note: MoMs are not huge so deltas do not give much benefit,
Expand All @@ -618,9 +623,10 @@ void remove_manifest_files(char *filename, int version, char *hash)
* getting the whole MoM and verifying it.
*
* Note that if the manifest fails to download, or if the manifest fails to be
* loaded into memory, this function will return NULL.
* loaded into memory, this function will return NULL. If err is passed, it is set
* with the error code.
*/
struct manifest *load_mom(int version, bool latest, bool mix_exists)
struct manifest *load_mom_err(int version, bool latest, bool mix_exists, int *err)
{
struct manifest *manifest = NULL;
int ret = 0;
Expand All @@ -635,6 +641,9 @@ struct manifest *load_mom(int version, bool latest, bool mix_exists)
ret = retrieve_manifests(version, version, "MoM", NULL, mix_exists);
if (ret != 0) {
fprintf(stderr, "Failed to retrieve %d MoM manifest\n", version);
if (err) {
*err = ret;
}
return NULL;
}

Expand All @@ -647,7 +656,10 @@ struct manifest *load_mom(int version, bool latest, bool mix_exists)
goto verify_mom;
}
fprintf(stderr, "Failed to load %d MoM manifest\n", version);
goto out;
if (err) {
*err = EMANIFEST_LOAD;
}
return NULL;
}

string_or_die(&filename, "%s/%i/Manifest.MoM", state_dir, version);
Expand All @@ -671,6 +683,9 @@ struct manifest *load_mom(int version, bool latest, bool mix_exists)
free_string(&filename);
free_string(&url);
free_manifest(manifest);
if (err) {
*err = ESIGNATURE;
}
return NULL;
}
fprintf(stderr, "FAILED TO VERIFY SIGNATURE OF Manifest.MoM. Operation proceeding due to\n"
Expand Down Expand Up @@ -698,9 +713,6 @@ struct manifest *load_mom(int version, bool latest, bool mix_exists)
free_string(&filename);
free_string(&url);
return manifest;

out:
return NULL;
}

/* Loads the MANIFEST for bundle associated with FILE at VERSION, referenced by
Expand Down
1 change: 1 addition & 0 deletions src/swupd.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ extern void apply_heuristics(struct file *file);

extern int file_sort_filename(const void *a, const void *b);
extern int file_sort_filename_reverse(const void *a, const void *b);
extern struct manifest *load_mom_err(int version, bool latest, bool mix_exists, int *err);
extern struct manifest *load_mom(int version, bool latest, bool mix_exists);
extern struct manifest *load_manifest(int current, int version, struct file *file, struct manifest *mom, bool header_only);
extern struct manifest *load_manifest_full(int version, bool mix);
Expand Down
11 changes: 8 additions & 3 deletions src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,20 @@ static int main_update()
load_server_mom:
grabtime_stop(&times); // Close step 2
grabtime_start(&times, "Recurse and Consolidate Manifests");
server_manifest = load_mom(server_version, true, mix_exists);
int server_manifest_err;
server_manifest = load_mom_err(server_version, true, mix_exists, &server_manifest_err);
if (!server_manifest) {
if (retries < MAX_TRIES) {
if (retries < MAX_TRIES && server_manifest_err != -ENET404) {
increment_retries(&retries, &timeout);
fprintf(stderr, "Retry #%d downloading server Manifests\n", retries);
goto load_server_mom;
}
fprintf(stderr, "Failure retrieving manifest from server\n");
fprintf(stderr, "Unable to load manifest after retrying (config or network problem?)\n");
if (server_manifest_err == -ENET404) {
fprintf(stderr, "Version %d not available\n", server_version);
} else {
fprintf(stderr, "Unable to load manifest after retrying (config or network problem?)\n");
}
ret = EMOM_NOTFOUND;
goto clean_exit;
}
Expand Down

0 comments on commit c2f3537

Please sign in to comment.