From 4211f24424a4b22b5941a52e8acd988a500488ee Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 16 Jul 2012 16:07:01 +0200 Subject: ipsw: implemented file locking for on-demand downloading --- src/ipsw.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/ipsw.c') diff --git a/src/ipsw.c b/src/ipsw.c index 033b894..8e3d598 100644 --- a/src/ipsw.c +++ b/src/ipsw.c @@ -26,6 +26,7 @@ #include #include "ipsw.h" +#include "locking.h" #include "idevicerestore.h" #define BUFSIZE 0x100000 @@ -403,6 +404,15 @@ int ipsw_download_latest_fw(plist_t version_data, const char* product, const cha char fwlfn[256]; sprintf(fwlfn, "%s/%s", todir, fwfn); + char fwlock[256]; + sprintf(fwlock, "%s.lock", fwlfn); + + lock_info_t lockinfo; + + if (lock_file(fwlock, &lockinfo) != 0) { + error("WARNING: Could not lock file '%s'\n", fwlock); + } + int need_dl = 0; unsigned char zsha1[20] = {0, }; FILE* f = fopen(fwlfn, "rb"); @@ -452,5 +462,10 @@ int ipsw_download_latest_fw(plist_t version_data, const char* product, const cha if (res == 0) { *ipswfile = strdup(fwlfn); } + + if (unlock_file(&lockinfo) != 0) { + error("WARNING: Could not unlock file '%s'\n", fwlock); + } + return res; } -- cgit v1.1-32-gdbae