summaryrefslogtreecommitdiffstats
path: root/src/idevicerestore.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-07-17 19:30:35 +0200
committerGravatar Nikias Bassen2012-07-17 19:30:35 +0200
commit078bed76bfefdb19bf26eac6b9869e5ab79afb05 (patch)
tree977ff083aa43ff9248b3b538f948784676d32d21 /src/idevicerestore.c
parent2d8ad559c605a3dbdfc7a8cab5bd95a1bf6279b0 (diff)
downloadidevicerestore-078bed76bfefdb19bf26eac6b9869e5ab79afb05.tar.gz
idevicerestore-078bed76bfefdb19bf26eac6b9869e5ab79afb05.tar.bz2
main: implement dynamic filesystem extraction (into cache dir)
Diffstat (limited to 'src/idevicerestore.c')
-rw-r--r--src/idevicerestore.c41
1 files changed, 36 insertions, 5 deletions
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 <fsname>.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 <fsname>.extract to <fsname>
+ rename(filesystem, tmpf);
+ }
}