mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-07 14:11:52 +00:00
helpers: Create helper link_or_rename()
Trying to link and on an error, rename the file was used more than once, so unifying in a helper function.
This commit is contained in:
committed by
Matthew Johnson
parent
07ae1ac8c5
commit
f0d3f333ef
+3
-8
@@ -27,7 +27,6 @@
|
||||
|
||||
static struct list *download_loop(struct list *files, bool free_list)
|
||||
{
|
||||
int ret;
|
||||
struct list *iter;
|
||||
unsigned int complete = 0;
|
||||
unsigned int list_length = list_len(files);
|
||||
@@ -55,13 +54,9 @@ static struct list *download_loop(struct list *files, bool free_list)
|
||||
string_or_die(&url, "%s/%i/files/%s.tar", MIX_STATE_DIR, file->last_change, file->hash);
|
||||
string_or_die(&file->staging, "%s/download/.%s.tar", state_dir, file->hash);
|
||||
|
||||
ret = link(url, file->staging);
|
||||
/* Try doing a regular rename if hardlink fails */
|
||||
if (ret) {
|
||||
if (rename(url, file->staging) != 0) {
|
||||
fprintf(stderr, "Failed to copy local mix file: %s\n", file->staging);
|
||||
continue;
|
||||
}
|
||||
if (link_or_rename(url, file->staging) != 0) {
|
||||
fprintf(stderr, "Failed to copy local mix file: %s\n", file->staging);
|
||||
continue;
|
||||
}
|
||||
untar_full_download(file);
|
||||
free_string(&url);
|
||||
|
||||
@@ -941,3 +941,15 @@ bool on_new_format(void)
|
||||
* different from the one we started on. */
|
||||
return !is_compatible_format(res);
|
||||
}
|
||||
|
||||
/* Try to create a link to a file. If it fails, rename it.
|
||||
* Return 0 on success or an error code on errors.*/
|
||||
int link_or_rename(const char *orig, const char *dest)
|
||||
{
|
||||
/* Try doing a regular rename if hardlink fails */
|
||||
if (link(orig, dest) != 0) {
|
||||
return rename(orig, dest);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-5
@@ -489,11 +489,7 @@ static int retrieve_manifests(int current, int version, char *component, struct
|
||||
if (is_mix) {
|
||||
string_or_die(&filename, "%s/%i/Manifest.%s.tar", state_dir, version, component);
|
||||
string_or_die(&url, "%s/%i/Manifest.%s.tar", basedir, version, component);
|
||||
ret = link(url, filename);
|
||||
/* Try doing a regular rename if hardlink fails */
|
||||
if (ret) {
|
||||
ret = rename(url, filename);
|
||||
}
|
||||
ret = link_or_rename(url, filename);
|
||||
/* If rename fails, we try again below with curl to the contenurl */
|
||||
if (ret == 0) {
|
||||
goto untar;
|
||||
|
||||
@@ -383,6 +383,7 @@ extern int list_installable_bundles();
|
||||
extern int install_bundles_frontend(char **bundles);
|
||||
extern int add_subscriptions(struct list *bundles, struct list **subs, int current_version, struct manifest *mom, bool find_all, int recursion);
|
||||
int list_local_bundles();
|
||||
extern int link_or_rename(const char *orig, const char *dest);
|
||||
|
||||
/* telemetry.c */
|
||||
typedef enum telem_prio_t {
|
||||
|
||||
Reference in New Issue
Block a user