zbackup/backup_exchanger.cc

49 lines
1.4 KiB
C++
Raw Normal View History

// Part of ZBackup. Licensed under GNU GPLv2 or later
#include "backup_exchanger.hh"
#include "dir.hh"
#include "debug.hh"
namespace BackupExchanger {
2014-10-02 22:13:15 +04:00
vector< string > recreateDirectories( string const & src, string const & dst, string const & relativePath )
{
vector< string > files;
2014-10-02 22:13:15 +04:00
Dir::Listing lst ( Dir::addPath( src, relativePath ) );
Dir::Entry entry;
while ( lst.getNext( entry ) )
{
2014-10-02 22:13:15 +04:00
string currentRelativePath ( relativePath );
if ( currentRelativePath.empty() )
currentRelativePath.assign( entry.getFileName() );
else
2014-10-02 22:13:15 +04:00
currentRelativePath.assign( Dir::addPath( relativePath, entry.getFileName() ) );
if ( entry.isDir() )
{
2014-10-02 22:13:15 +04:00
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() ) )
{
verbosePrintf( "Directory %s not found in destination, creating...\n",
2014-10-02 22:13:15 +04:00
currentRelativePath.c_str() );
Dir::create( dstFullPath.c_str() );
}
2014-10-02 22:13:15 +04:00
vector< string > subFiles ( recreateDirectories( src, dst, currentRelativePath ) );
files.insert( files.end(), subFiles.begin(), subFiles.end() );
}
else
{
2014-10-02 22:13:15 +04:00
verbosePrintf( "Found file %s...\n", currentRelativePath.c_str() );
files.push_back( currentRelativePath );
}
}
return files;
}
}