@ -10,6 +10,7 @@
# include "util.h"
# include "util.h"
# include "chainparamsbase.h"
# include "chainparamsbase.h"
# include "fs.h"
# include "random.h"
# include "random.h"
# include "serialize.h"
# include "serialize.h"
# include "sync.h"
# include "sync.h"
@ -79,8 +80,6 @@
# include <boost/algorithm/string/case_conv.hpp> // for to_lower()
# include <boost/algorithm/string/case_conv.hpp> // for to_lower()
# include <boost/algorithm/string/join.hpp>
# include <boost/algorithm/string/join.hpp>
# include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
# include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
# include <boost/filesystem.hpp>
# include <boost/filesystem/fstream.hpp>
# include <boost/foreach.hpp>
# include <boost/foreach.hpp>
# include <boost/program_options/detail/config_file.hpp>
# include <boost/program_options/detail/config_file.hpp>
# include <boost/program_options/parsers.hpp>
# include <boost/program_options/parsers.hpp>
@ -215,8 +214,8 @@ void OpenDebugLog()
assert ( fileout = = NULL ) ;
assert ( fileout = = NULL ) ;
assert ( vMsgsBeforeOpenLog ) ;
assert ( vMsgsBeforeOpenLog ) ;
boost : : file system : : path pathDebug = GetDataDir ( ) / " debug.log " ;
fs : : path pathDebug = GetDataDir ( ) / " debug.log " ;
fileout = fopen ( pathDebug . string ( ) . c_str ( ) , " a " ) ;
fileout = fsbridge : : fopen ( pathDebug , " a " ) ;
if ( fileout ) {
if ( fileout ) {
setbuf ( fileout , NULL ) ; // unbuffered
setbuf ( fileout , NULL ) ; // unbuffered
// dump buffered messages from before we opened the log
// dump buffered messages from before we opened the log
@ -354,8 +353,8 @@ int LogPrintStr(const std::string &str)
// reopen the log file, if requested
// reopen the log file, if requested
if ( fReopenDebugLog ) {
if ( fReopenDebugLog ) {
fReopenDebugLog = false ;
fReopenDebugLog = false ;
boost : : file system : : path pathDebug = GetDataDir ( ) / " debug.log " ;
fs : : path pathDebug = GetDataDir ( ) / " debug.log " ;
if ( freopen ( pathDebug . string ( ) . c_str ( ) , " a " , fileout ) ! = NULL )
if ( fsbridge : : freopen ( pathDebug , " a " , fileout ) ! = NULL )
setbuf ( fileout , NULL ) ; // unbuffered
setbuf ( fileout , NULL ) ; // unbuffered
}
}
@ -512,9 +511,8 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
fprintf ( stderr , " \n \n ************************ \n %s \n " , message . c_str ( ) ) ;
fprintf ( stderr , " \n \n ************************ \n %s \n " , message . c_str ( ) ) ;
}
}
boost : : file system : : path GetDefaultDataDir ( )
fs : : path GetDefaultDataDir ( )
{
{
namespace fs = boost : : filesystem ;
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
// Mac: ~/Library/Application Support/Bitcoin
// Mac: ~/Library/Application Support/Bitcoin
@ -539,13 +537,12 @@ boost::filesystem::path GetDefaultDataDir()
# endif
# endif
}
}
static boost : : file system : : path pathCached ;
static fs : : path pathCached ;
static boost : : file system : : path pathCachedNetSpecific ;
static fs : : path pathCachedNetSpecific ;
static CCriticalSection csPathCached ;
static CCriticalSection csPathCached ;
const boost : : file system : : path & GetDataDir ( bool fNetSpecific )
const fs : : path & GetDataDir ( bool fNetSpecific )
{
{
namespace fs = boost : : filesystem ;
LOCK ( csPathCached ) ;
LOCK ( csPathCached ) ;
@ -577,13 +574,13 @@ void ClearDatadirCache()
{
{
LOCK ( csPathCached ) ;
LOCK ( csPathCached ) ;
pathCached = boost : : file system : : path ( ) ;
pathCached = fs : : path ( ) ;
pathCachedNetSpecific = boost : : file system : : path ( ) ;
pathCachedNetSpecific = fs : : path ( ) ;
}
}
boost : : file system : : path GetConfigFile ( const std : : string & confPath )
fs : : path GetConfigFile ( const std : : string & confPath )
{
{
boost : : file system : : path pathConfigFile ( confPath ) ;
fs : : path pathConfigFile ( confPath ) ;
if ( ! pathConfigFile . is_complete ( ) )
if ( ! pathConfigFile . is_complete ( ) )
pathConfigFile = GetDataDir ( false ) / pathConfigFile ;
pathConfigFile = GetDataDir ( false ) / pathConfigFile ;
@ -592,7 +589,7 @@ boost::filesystem::path GetConfigFile(const std::string& confPath)
void ReadConfigFile ( const std : : string & confPath )
void ReadConfigFile ( const std : : string & confPath )
{
{
boost : : file system : : ifstream streamConfig ( GetConfigFile ( confPath ) ) ;
fs : : ifstream streamConfig ( GetConfigFile ( confPath ) ) ;
if ( ! streamConfig . good ( ) )
if ( ! streamConfig . good ( ) )
return ; // No bitcoin.conf file is OK
return ; // No bitcoin.conf file is OK
@ -617,16 +614,16 @@ void ReadConfigFile(const std::string& confPath)
}
}
# ifndef WIN32
# ifndef WIN32
boost : : file system : : path GetPidFile ( )
fs : : path GetPidFile ( )
{
{
boost : : file system : : path pathPidFile ( GetArg ( " -pid " , BITCOIN_PID_FILENAME ) ) ;
fs : : path pathPidFile ( GetArg ( " -pid " , BITCOIN_PID_FILENAME ) ) ;
if ( ! pathPidFile . is_complete ( ) ) pathPidFile = GetDataDir ( ) / pathPidFile ;
if ( ! pathPidFile . is_complete ( ) ) pathPidFile = GetDataDir ( ) / pathPidFile ;
return pathPidFile ;
return pathPidFile ;
}
}
void CreatePidFile ( const boost : : file system : : path & path , pid_t pid )
void CreatePidFile ( const fs : : path & path , pid_t pid )
{
{
FILE * file = fopen ( path . string ( ) . c_str ( ) , " w " ) ;
FILE * file = fsbridge : : fopen ( path , " w " ) ;
if ( file )
if ( file )
{
{
fprintf ( file , " %d \n " , pid ) ;
fprintf ( file , " %d \n " , pid ) ;
@ -635,7 +632,7 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
}
}
# endif
# endif
bool RenameOver ( boost : : file system : : path src , boost : : file system : : path dest )
bool RenameOver ( fs : : path src , fs : : path dest )
{
{
# ifdef WIN32
# ifdef WIN32
return MoveFileExA ( src . string ( ) . c_str ( ) , dest . string ( ) . c_str ( ) ,
return MoveFileExA ( src . string ( ) . c_str ( ) , dest . string ( ) . c_str ( ) ,
@ -651,13 +648,13 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
* Specifically handles case where path p exists , but it wasn ' t possible for the user to
* Specifically handles case where path p exists , but it wasn ' t possible for the user to
* write to the parent directory .
* write to the parent directory .
*/
*/
bool TryCreateDirectory ( const boost : : file system : : path & p )
bool TryCreateDirectory ( const fs : : path & p )
{
{
try
try
{
{
return boost : : file system : : create_directory ( p ) ;
return fs : : create_directory ( p ) ;
} catch ( const boost : : file system : : filesystem_error & ) {
} catch ( const fs : : filesystem_error & ) {
if ( ! boost : : file system : : exists ( p ) | | ! boost : : file system : : is_directory ( p ) )
if ( ! fs : : exists ( p ) | | ! fs : : is_directory ( p ) )
throw ;
throw ;
}
}
@ -764,11 +761,11 @@ void ShrinkDebugFile()
// Amount of debug.log to save at end when shrinking (must fit in memory)
// Amount of debug.log to save at end when shrinking (must fit in memory)
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000 ;
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000 ;
// Scroll debug.log if it's getting too big
// Scroll debug.log if it's getting too big
boost : : file system : : path pathLog = GetDataDir ( ) / " debug.log " ;
fs : : path pathLog = GetDataDir ( ) / " debug.log " ;
FILE * file = fopen ( pathLog . string ( ) . c_str ( ) , " r " ) ;
FILE * file = fsbridge : : fopen ( pathLog , " r " ) ;
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
if ( file & & boost : : file system : : file_size ( pathLog ) > 11 * ( RECENT_DEBUG_HISTORY_SIZE / 10 ) )
if ( file & & fs : : file_size ( pathLog ) > 11 * ( RECENT_DEBUG_HISTORY_SIZE / 10 ) )
{
{
// Restart the file with some of the end
// Restart the file with some of the end
std : : vector < char > vch ( RECENT_DEBUG_HISTORY_SIZE , 0 ) ;
std : : vector < char > vch ( RECENT_DEBUG_HISTORY_SIZE , 0 ) ;
@ -776,7 +773,7 @@ void ShrinkDebugFile()
int nBytes = fread ( vch . data ( ) , 1 , vch . size ( ) , file ) ;
int nBytes = fread ( vch . data ( ) , 1 , vch . size ( ) , file ) ;
fclose ( file ) ;
fclose ( file ) ;
file = fopen ( pathLog . string ( ) . c_str ( ) , " w " ) ;
file = fsbridge : : fopen ( pathLog , " w " ) ;
if ( file )
if ( file )
{
{
fwrite ( vch . data ( ) , 1 , nBytes , file ) ;
fwrite ( vch . data ( ) , 1 , nBytes , file ) ;
@ -788,10 +785,8 @@ void ShrinkDebugFile()
}
}
# ifdef WIN32
# ifdef WIN32
boost : : file system : : path GetSpecialFolderPath ( int nFolder , bool fCreate )
fs : : path GetSpecialFolderPath ( int nFolder , bool fCreate )
{
{
namespace fs = boost : : filesystem ;
char pszPath [ MAX_PATH ] = " " ;
char pszPath [ MAX_PATH ] = " " ;
if ( SHGetSpecialFolderPathA ( NULL , pszPath , nFolder , fCreate ) )
if ( SHGetSpecialFolderPathA ( NULL , pszPath , nFolder , fCreate ) )
@ -851,9 +846,9 @@ void SetupEnvironment()
// The path locale is lazy initialized and to avoid deinitialization errors
// The path locale is lazy initialized and to avoid deinitialization errors
// in multithreading environments, it is set explicitly by the main thread.
// in multithreading environments, it is set explicitly by the main thread.
// A dummy locale is used to extract the internal default locale, used by
// A dummy locale is used to extract the internal default locale, used by
// boost:: file system ::path, which is then used to explicitly imbue the path.
// fs::path, which is then used to explicitly imbue the path.
std : : locale loc = boost : : file system : : path : : imbue ( std : : locale : : classic ( ) ) ;
std : : locale loc = fs : : path : : imbue ( std : : locale : : classic ( ) ) ;
boost : : file system : : path : : imbue ( loc ) ;
fs : : path : : imbue ( loc ) ;
}
}
bool SetupNetworking ( )
bool SetupNetworking ( )