Fix for #50 and additional workaround for #48

master
Vladimir Stackov 2015-01-25 19:33:01 +03:00
parent 3bde1c404e
commit 4298a0f111
5 changed files with 25 additions and 19 deletions

View File

@ -10,6 +10,7 @@
#include "chunk_index.hh"
#include "backup_restorer.hh"
#include "backup_file.hh"
#include "backup_exchanger.hh"
#include "debug.hh"
@ -138,9 +139,6 @@ void ZCollector::gc()
chunkReindex, getBundlesPath(), getIndexPath(), config.runtime.threads );
string fileName;
string backupsPath = getBackupsPath();
Dir::Listing lst( backupsPath );
Dir::Entry entry;
@ -152,13 +150,18 @@ void ZCollector::gc()
verbosePrintf( "Checking used chunks...\n" );
while( lst.getNext( entry ) )
verbosePrintf( "Searching for backups...\n" );
vector< string > backups = BackupExchanger::findOrRebuild( getBackupsPath() );
for ( std::vector< string >::iterator it = backups.begin(); it != backups.end(); ++it )
{
verbosePrintf( "Checking backup %s...\n", entry.getFileName().c_str() );
string backup( Dir::addPath( getBackupsPath(), *it ) );
verbosePrintf( "Checking backup %s...\n", backup.c_str() );
BackupInfo backupInfo;
BackupFile::load( Dir::addPath( backupsPath, entry.getFileName() ), encryptionkey, backupInfo );
BackupFile::load( backup, encryptionkey, backupInfo );
string backupData;
@ -180,10 +183,11 @@ void ZCollector::gc()
while( bundleLst.getNext( entry ) )
{
const string dirPath = Dir::addPath( bundlesPath, entry.getFileName());
if (entry.isDir() && Dir::isDirEmpty(dirPath)) {
Dir::remove(dirPath);
if ( entry.isDir() && Dir::isDirEmpty( dirPath ) )
{
Dir::remove( dirPath );
}
}
verbosePrintf( "Garbage collection complete\n" );
}

View File

@ -7,7 +7,7 @@
namespace BackupExchanger {
vector< string > recreateDirectories( string const & src, string const & dst, string const & relativePath )
vector< string > findOrRebuild( string const & src, string const & dst, string const & relativePath )
{
vector< string > files;
@ -26,15 +26,15 @@ vector< string > recreateDirectories( string const & src, string const & dst, st
if ( entry.isDir() )
{
verbosePrintf( "Found directory %s...\n", currentRelativePath.c_str() );
string srcFullPath ( Dir::addPath( src, currentRelativePath ) );
string dstFullPath ( Dir::addPath( dst, currentRelativePath ) );
if ( !Dir::exists( dstFullPath.c_str() ) )
string srcFullPath( Dir::addPath( src, currentRelativePath ) );
string dstFullPath( Dir::addPath( dst, currentRelativePath ) );
if ( !dst.empty() && !Dir::exists( dstFullPath.c_str() ) )
{
verbosePrintf( "Directory %s not found in destination, creating...\n",
currentRelativePath.c_str() );
Dir::create( dstFullPath.c_str() );
}
vector< string > subFiles ( recreateDirectories( src, dst, currentRelativePath ) );
vector< string > subFiles( findOrRebuild( src, dst, currentRelativePath ) );
files.insert( files.end(), subFiles.begin(), subFiles.end() );
}
else

View File

@ -22,7 +22,9 @@ enum {
};
/// Recreate source directory structure in destination
vector< string > recreateDirectories( string const & src, string const & dst, string const & relativePath = std::string() );
vector< string > findOrRebuild( string const & src,
string const & dst = std::string(),
string const & relativePath = std::string() );
typedef pair< sptr< TemporaryFile >, string > PendingExchangeRename;
}

View File

@ -143,7 +143,7 @@ Config::~Config()
}
Config::Config():
want_cleanup( true )
want_cleanup( false )
{
ConfigInfo * configInfo = new ConfigInfo;
storable = configInfo;

View File

@ -178,7 +178,7 @@ void ZExchange::exchange()
{
verbosePrintf( "Searching for bundles...\n" );
vector< string > bundles = BackupExchanger::recreateDirectories(
vector< string > bundles = BackupExchanger::findOrRebuild(
srcZBackupBase.getBundlesPath(), dstZBackupBase.getBundlesPath() );
for ( std::vector< string >::iterator it = bundles.begin(); it != bundles.end(); ++it )
@ -214,7 +214,7 @@ void ZExchange::exchange()
if ( config.runtime.exchange.test( BackupExchanger::index ) )
{
verbosePrintf( "Searching for indicies...\n" );
vector< string > indicies = BackupExchanger::recreateDirectories(
vector< string > indicies = BackupExchanger::findOrRebuild(
srcZBackupBase.getIndexPath(), dstZBackupBase.getIndexPath() );
for ( std::vector< string >::iterator it = indicies.begin(); it != indicies.end(); ++it )
@ -259,7 +259,7 @@ void ZExchange::exchange()
BackupInfo backupInfo;
verbosePrintf( "Searching for backups...\n" );
vector< string > backups = BackupExchanger::recreateDirectories(
vector< string > backups = BackupExchanger::findOrRebuild(
srcZBackupBase.getBackupsPath(), dstZBackupBase.getBackupsPath() );
for ( std::vector< string >::iterator it = backups.begin(); it != backups.end(); ++it )