diff options
author | Nikias Bassen | 2012-07-16 16:09:03 +0200 |
---|---|---|
committer | Nikias Bassen | 2012-07-16 16:09:03 +0200 |
commit | 8e6134babc8cc520d136fb067c7ac6b9dd7c17d2 (patch) | |
tree | 563f89f71ab86f6e822b370a746c42ae69fb7264 | |
parent | f0d950b94f9baeeb311663de26c5a68ff58bb3f5 (diff) | |
download | idevicerestore-8e6134babc8cc520d136fb067c7ac6b9dd7c17d2.tar.gz idevicerestore-8e6134babc8cc520d136fb067c7ac6b9dd7c17d2.tar.bz2 |
main: use file locking for version.xml updating
-rw-r--r-- | src/idevicerestore.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/idevicerestore.c b/src/idevicerestore.c index e0a9e9c..a8e03a5 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -40,6 +40,8 @@ #include "limera1n.h" +#include "locking.h" + #define VERSION_XML "cache/version.xml" int use_apple_server; @@ -94,6 +96,11 @@ static int load_version_data(struct idevicerestore_client_t* client) struct stat fst; int cached = 0; + lock_info_t lockinfo; + if (lock_file(VERSION_XML ".lock", &lockinfo) != 0) { + error("WARNING: could not lock file\n"); + } + if ((stat(VERSION_XML, &fst) < 0) || ((time(NULL)-86400) > fst.st_mtime)) { __mkdir("cache", 0755); @@ -112,6 +119,11 @@ static int load_version_data(struct idevicerestore_client_t* client) char *verbuf = NULL; size_t verlen = 0; read_file(VERSION_XML, (void**)&verbuf, &verlen); + + if (unlock_file(&lockinfo) != 0) { + error("WARNING: could not unlock file\n"); + } + if (!verbuf) { error("ERROR: Could not load '" VERSION_XML "'.\n"); return -1; |