aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 36dfd8ab7..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
@@ -1107,16 +1124,6 @@ void FileCommit(FILE *fileout)
#endif
}
-int GetFilesize(FILE* file)
-{
- int nSavePos = ftell(file);
- int nFilesize = -1;
- if (fseek(file, 0, SEEK_END) == 0)
- nFilesize = ftell(file);
- fseek(file, nSavePos, SEEK_SET);
- return nFilesize;
-}
-
bool TruncateFile(FILE *file, unsigned int length) {
#if defined(WIN32)
return _chsize(_fileno(file), length) == 0;
@@ -1195,7 +1202,7 @@ void ShrinkDebugFile()
// Scroll debug.log if it's getting too big
boost::filesystem::path pathLog = GetDataDir() / "debug.log";
FILE* file = fopen(pathLog.string().c_str(), "r");
- if (file && GetFilesize(file) > 10 * 1000000)
+ if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
{
// Restart the file with some of the end
char pch[200000];
@@ -1214,13 +1221,6 @@ void ShrinkDebugFile()
fclose(file);
}
-
-
-
-
-
-
-
//
// "Never go to sea with two chronometers; take one or three."
// Our three time sources are: