From 4298a0f11160e948a12b205ee99e2837f4e22eec Mon Sep 17 00:00:00 2001 From: Vladimir Stackov Date: Sun, 25 Jan 2015 19:33:01 +0300 Subject: [PATCH] Fix for #50 and additional workaround for #48 --- backup_collector.cc | 22 +++++++++++++--------- backup_exchanger.cc | 10 +++++----- backup_exchanger.hh | 4 +++- config.cc | 2 +- zbackup.cc | 6 +++--- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/backup_collector.cc b/backup_collector.cc index b276f2c..1b29b84 100644 --- a/backup_collector.cc +++ b/backup_collector.cc @@ -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" ); } diff --git a/backup_exchanger.cc b/backup_exchanger.cc index 5cd1a7f..070cdd8 100644 --- a/backup_exchanger.cc +++ b/backup_exchanger.cc @@ -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 diff --git a/backup_exchanger.hh b/backup_exchanger.hh index afface2..d2f0229 100644 --- a/backup_exchanger.hh +++ b/backup_exchanger.hh @@ -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; } diff --git a/config.cc b/config.cc index e229a30..2d2873b 100644 --- a/config.cc +++ b/config.cc @@ -143,7 +143,7 @@ Config::~Config() } Config::Config(): - want_cleanup( true ) + want_cleanup( false ) { ConfigInfo * configInfo = new ConfigInfo; storable = configInfo; diff --git a/zbackup.cc b/zbackup.cc index fabec50..cfb5e88 100644 --- a/zbackup.cc +++ b/zbackup.cc @@ -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 )