diff options
| author | Brandon Dahler <[email protected]> | 2014-03-23 20:14:43 -0500 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2014-03-31 09:51:58 +0200 |
| commit | 2b7709dc84ed37128c125ca7a97b2e4b2c4437e7 (patch) | |
| tree | 398d4f480d88291e7c3b73c193d31eb63cb9e6f4 /src/util.cpp | |
| parent | Merge pull request #3987 from laanwj/2014_03_icreatemultisig (diff) | |
| download | discoin-2b7709dc84ed37128c125ca7a97b2e4b2c4437e7.tar.xz discoin-2b7709dc84ed37128c125ca7a97b2e4b2c4437e7.zip | |
Wrap create_directory calls in try...catch blocks.
Ignores any exceptions thrown if directory exists, otherwise re-throws exception.
Rebased-By: Wladimir J. van der Laan <[email protected]>
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp index b90921ab8..a919b4b85 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -976,7 +976,7 @@ boost::filesystem::path GetDefaultDataDir() #ifdef MAC_OSX // Mac pathRet /= "Library/Application Support"; - fs::create_directory(pathRet); + TryCreateDirectory(pathRet); return pathRet / "Bitcoin"; #else // Unix @@ -1090,6 +1090,23 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) #endif /* WIN32 */ } + +// Ignores exceptions thrown by boost's create_directory if the requested directory exists. +// Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory. +bool TryCreateDirectory(const boost::filesystem::path& p) +{ + try + { + return boost::filesystem::create_directory(p); + } catch (boost::filesystem::filesystem_error) { + if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p)) + throw; + } + + // create_directory didn't create the directory, it had to have existed already + return false; +} + void FileCommit(FILE *fileout) { fflush(fileout); // harmless if redundantly called |