--- loader/loader.c | 11 ++++++- loader/loadermisc.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- loader/loadermisc.h | 1 + 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index dd563c9..f33e6e8 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -1712,11 +1712,18 @@ 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; puts("Restarting Anaconda."); unlink("/tmp/restart_anaconda"); + if (loaderData->updatessrc) { + int updates_fd = open("/tmp/updates", O_RDONLY); + if (recursiveRemove(updates_fd)) + fprintf(stderr, "Error removing /tmp/updates. Updates won't be re-downloaded."); + else + loadUpdatesFromRemote(loaderData->updatessrc, loaderData); + } return 1; } @@ -2352,7 +2359,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..d476a76 100644 --- a/loader/loadermisc.c +++ b/loader/loadermisc.c @@ -25,15 +25,17 @@ */ #include <ctype.h> +#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <string.h> #include <unistd.h> #include <stdarg.h> #include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> #include "../isys/log.h" - #include "windows.h" int copyFileFd(int infd, char * dest, progressCB pbcb, @@ -87,6 +89,77 @@ int copyFile(char * source, char * dest) { return rc; } +/** + * 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. + * + * This is copied from the util-linux-ng project. + */ +int recursiveRemove(int fd) +{ + struct stat rb; + DIR *dir; + int rc = -1; + int dfd; + + if (!(dir = fdopendir(fd))) { + goto done; + } + + /* fdopendir() precludes us from continuing to use the input fd */ + dfd = dirfd(dir); + + if (fstat(dfd, &rb)) { + goto done; + } + + while(1) { + struct dirent *d; + + errno = 0; + if (!(d = readdir(dir))) { + if (errno) { + goto done; + } + break; /* end of directory */ + } + + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + + if (d->d_type == DT_DIR) { + struct stat sb; + + if (fstatat(dfd, d->d_name, &sb, AT_SYMLINK_NOFOLLOW)) { + continue; + } + + /* remove subdirectories if device is same as dir */ + if (sb.st_dev == rb.st_dev) { + int cfd; + + cfd = openat(dfd, d->d_name, O_RDONLY); + if (cfd >= 0) { + recursiveRemove(cfd); + close(cfd); + } + } else + continue; + } + + unlinkat(dfd, d->d_name, d->d_type == DT_DIR ? AT_REMOVEDIR : 0); + } + + rc = 0; /* success */ + + done: + if (dir) + closedir(dir); + return rc; +} + 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..8dec2e4 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 recursiveRemove(int fd); 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