From: Arvin Schnell Date: Thu, 21 Apr 2011 09:39:43 +0000 (+0200) Subject: - handle EEXIST when creating new snapshot X-Git-Tag: v0.1.3~403 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72470f485e00d5f661fcf1f7aa948d7e20c0ebc4;p=thirdparty%2Fsnapper.git - handle EEXIST when creating new snapshot --- diff --git a/snapper/Compare.h b/snapper/Compare.h index 3b35d7a3..b17fa756 100644 --- a/snapper/Compare.h +++ b/snapper/Compare.h @@ -33,13 +33,6 @@ namespace snapper using std::string; - struct IOErrorException : public std::exception - { - explicit IOErrorException() throw() {} - virtual const char* what() const throw() { return "IO error"; } - }; - - typedef std::function cmpdirs_cb_t; diff --git a/snapper/Exception.h b/snapper/Exception.h index fab206d6..e63ca97d 100644 --- a/snapper/Exception.h +++ b/snapper/Exception.h @@ -49,6 +49,12 @@ namespace snapper virtual const char* what() const throw() { return "logic error"; } }; + struct IOErrorException : public std::exception + { + explicit IOErrorException() throw() {} + virtual const char* what() const throw() { return "IO error"; } + }; + } diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index d33050f1..14e55376 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -273,9 +273,13 @@ namespace snapper if (!entries.empty()) num = entries.rbegin()->num + 1; - mkdir((snapper->snapshotsDir() + "/" + decString(num)).c_str(), 0777); + int r; + while ((r = mkdir((snapper->snapshotsDir() + "/" + decString(num)).c_str(), 0777)) == -1 && + errno == EEXIST) + ++num; - // TODO check EEXIST + if (r != 0) + throw IOErrorException(); return num; }