[master 2/2] Redownload and extract updates.img during anaconda restart.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/loader.c     |   10 ++++++++--
 loader/loadermisc.c |   34 ++++++++++++++++++++++++++++++++++
 loader/loadermisc.h |    1 +
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index 6a701e4..d9c0589 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1712,9 +1712,15 @@ void loaderUsrXHandler(int signum) {
     init_sig = signum;
 }
 
-int restart_anaconda() {
+int restart_anaconda(struct loaderData_s *loaderData) {
     if (access("/tmp/restart_anaconda", R_OK))
         return 0;
+    if (loaderData->updatessrc) {
+        if (rm_rf("/tmp/updates"))
+            fprintf(stderr, "Error removing /tmp/updates. Updates won't be re-downloaded.");
+        else
+            loadUpdatesFromRemote(loaderData->updatessrc, loaderData);
+    }
     puts("Restarting Anaconda.");
     return 1;
 }
@@ -2351,7 +2357,7 @@ int main(int argc, char ** argv) {
             }
         }
         waitpid(pid, &status, 0);
-    } while (restart_anaconda());
+    } while (restart_anaconda(&loaderData));
 
     if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) {
         rc = 1;
diff --git a/loader/loadermisc.c b/loader/loadermisc.c
index 2e667f5..b9e64f0 100644
--- a/loader/loadermisc.c
+++ b/loader/loadermisc.c
@@ -87,6 +87,40 @@ int copyFile(char * source, char * dest) {
     return rc;
 }
 
+int rm_rf(const char* target) {
+    /**
+     * Do "rm -rf" on the target directory.
+     *
+     * Returns 0 on success, nonzero otherwise (i.e. directory doesn't exist or
+     * some of its contents couldn't be removed.
+     */
+    DIR* dir = opendir(target);
+    if (!dir)
+        return(1);
+    struct dirent* ent;
+    char* entrypath;
+    while ((ent=readdir(dir))) {
+        if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+            continue;
+        asprintf(&entrypath, "%s/%s", target, ent->d_name);
+        if (ent->d_type == DT_DIR) {
+            if (rm_rf(entrypath))
+                goto error;
+        }
+        else {
+            if (remove(entrypath))
+                goto error;
+        }
+    }
+    if (remove(target))
+        goto error;
+    closedir(dir);
+    return(0);
+ error:
+    closedir(dir);
+    return(1);
+}
+
 int simpleStringCmp(const void * a, const void * b) {
     const char * first = *((const char **) a);
     const char * second = *((const char **) b);
diff --git a/loader/loadermisc.h b/loader/loadermisc.h
index 23ebf4a..3d80791 100644
--- a/loader/loadermisc.h
+++ b/loader/loadermisc.h
@@ -27,6 +27,7 @@
 int copyFile(char * source, char * dest);
 int copyFileFd(int infd, char * dest, progressCB pbcb,
                struct progressCBdata *data, long long total);
+int rm_rf(const char* target);
 int simpleStringCmp(const void * a, const void * b);
 int totalMemory(void);
 
-- 
1.6.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux