Skip to content

Commit

Permalink
Resolves zbackup#76
Browse files Browse the repository at this point in the history
Now it was possible to specify path to tmp directory using TMPDIR
environment variable, i.e.:
cat /111 | TMPDIR=/tmp/ zbackup backup -O paths.respect_tmp <..>
  • Loading branch information
Vlad1mir-D committed Aug 20, 2015
1 parent ff11399 commit 4bd4fa8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
18 changes: 18 additions & 0 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
}
};
Expand All @@ -61,6 +63,7 @@ public:
oRuntime_cacheSize,
oRuntime_exchange,
oRuntime_gcRepack,
oRuntime_pathsRespectTmp,

oDeprecated, oUnsupported
} OpCodes;
Expand Down
15 changes: 13 additions & 2 deletions zbackup_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
}

Expand Down Expand Up @@ -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 ) ),
Expand Down Expand Up @@ -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 ) ),
Expand Down
2 changes: 2 additions & 0 deletions zbackup_base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4bd4fa8

Please sign in to comment.