diff --git a/config.cc b/config.cc index 32ce6f5..2cf1573 100644 --- a/config.cc +++ b/config.cc @@ -133,6 +133,15 @@ void Config::prefillKeywords() "Not default, you should specify it explicitly." }, + { + "paths.respect_tmp", + Config::oRuntime_pathsRespectTmp, + Config::Runtime, + "ZBackup will use TMPDIR environment variable\n" + "for temporary files if set.\n" + "Not default, you should specify it explicitly." + }, + { "", Config::oBadOption, Config::None } }; @@ -475,6 +484,15 @@ bool Config::parseOrValidate( const string & option, const OptionType type, /* NOTREACHED */ break; + case oRuntime_pathsRespectTmp: + runtime.pathsRespectTmp = true; + + dPrintf( "runtime[pathsRespectTmp] = true\n" ); + + return true; + /* NOTREACHED */ + break; + case oBadOption: default: return false; diff --git a/config.hh b/config.hh index a721055..eb48700 100644 --- a/config.hh +++ b/config.hh @@ -30,12 +30,14 @@ public: size_t cacheSize; bitset< BackupExchanger::Flags > exchange; bool gcRepack; + bool pathsRespectTmp; // Default runtime config RuntimeConfig(): threads( getNumberOfCpus() ), cacheSize( 40 * 1024 * 1024 ), // 40 MB - gcRepack ( false ) + gcRepack ( false ), + pathsRespectTmp( false ) { } }; @@ -61,6 +63,7 @@ public: oRuntime_cacheSize, oRuntime_exchange, oRuntime_gcRepack, + oRuntime_pathsRespectTmp, oDeprecated, oUnsupported } OpCodes; diff --git a/zbackup_base.cc b/zbackup_base.cc index 1765fe2..5268716 100644 --- a/zbackup_base.cc +++ b/zbackup_base.cc @@ -29,8 +29,19 @@ Paths::Paths( string const & storageDir ): storageDir( storageDir ) { } +Paths::Paths( string const & storageDir, Config const & config ): + storageDir( storageDir ), config( config ) +{ +} + string Paths::getTmpPath() { + if ( config.runtime.pathsRespectTmp ) + { + char * tmpdir; + if ( ( ( tmpdir = getenv( "TMPDIR" ) ) != NULL && *tmpdir != '\0' ) ) + return string( tmpdir ); + } return string( Dir::addPath( storageDir, "tmp" ) ); } @@ -75,7 +86,7 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password ): ZBackupBase::ZBackupBase( string const & storageDir, string const & password, Config & configIn ): - Paths( storageDir ), storageInfo( loadStorageInfo() ), + Paths( storageDir, configIn ), storageInfo( loadStorageInfo() ), encryptionkey( password, storageInfo.has_encryption_key() ? &storageInfo.encryption_key() : 0 ), extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), @@ -105,7 +116,7 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password, ZBackupBase::ZBackupBase( string const & storageDir, string const & password, Config & configIn, bool prohibitChunkIndexLoading ): - Paths( storageDir ), storageInfo( loadStorageInfo() ), + Paths( storageDir, configIn ), storageInfo( loadStorageInfo() ), encryptionkey( password, storageInfo.has_encryption_key() ? &storageInfo.encryption_key() : 0 ), extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), diff --git a/zbackup_base.hh b/zbackup_base.hh index 96a9f08..2cce265 100644 --- a/zbackup_base.hh +++ b/zbackup_base.hh @@ -13,9 +13,11 @@ struct Paths { + Config config; std::string storageDir; Paths( std::string const & storageDir ); + Paths( std::string const & storageDir, Config const & ); std::string getTmpPath(); std::string getRestorePath();