From 078bed76bfefdb19bf26eac6b9869e5ab79afb05 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 17 Jul 2012 19:30:35 +0200 Subject: main: implement dynamic filesystem extraction (into cache dir) --- src/idevicerestore.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'src/idevicerestore.c') diff --git a/src/idevicerestore.c b/src/idevicerestore.c index c5f6dbb..e546864 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -713,6 +713,10 @@ int main(int argc, char* argv[]) { if (p) { *p = '\0'; } + + if (stat(tmpf, &st) < 0) { + __mkdir(tmpf, 0755); + } strcat(tmpf, "/"); strcat(tmpf, fsname); @@ -727,12 +731,34 @@ int main(int argc, char* argv[]) { } if (!filesystem) { - filesystem = tempnam(NULL, "ipsw_"); - if (!filesystem) { - error("WARNING: Could not get temporary filename!\n"); - filesystem = strdup(fsname); + char extfn[1024]; + strcpy(extfn, tmpf); + strcat(extfn, ".extract"); + char lockfn[1024]; + strcpy(lockfn, tmpf); + strcat(lockfn, ".lock"); + lock_info_t li; + + lock_file(lockfn, &li); + FILE* extf = NULL; + if (access(extfn, F_OK) != 0) { + extf = fopen(extfn, "w"); } - delete_fs = 1; + unlock_file(&li); + if (!extf) { + // use temp filename + filesystem = tempnam(NULL, "ipsw_"); + if (!filesystem) { + error("WARNING: Could not get temporary filename, using '%s' in current directory\n", fsname); + filesystem = strdup(fsname); + } + delete_fs = 1; + } else { + // use .extract as filename + filesystem = strdup(extfn); + fclose(extf); + } + remove(lockfn); // Extract filesystem from IPSW info("Extracting filesystem from IPSW\n"); @@ -743,6 +769,11 @@ int main(int argc, char* argv[]) { plist_free(buildmanifest); return -1; } + + if (strstr(filesystem, ".extract")) { + // rename .extract to + rename(filesystem, tmpf); + } } -- cgit v1.1-32-gdbae