mirror of https://github.com/vitalif/zbackup
Removing empty directories in bundles after performing garbage collection
Signed-off-by: Gleb Golubitsky <sectoid@gnolltech.org>master
parent
3522786202
commit
3747a3e5c4
7
dir.cc
7
dir.cc
|
@ -66,6 +66,13 @@ string getDirName( string const & path )
|
|||
return dirname( copy.data() );
|
||||
}
|
||||
|
||||
bool isDirEmpty( string const & path )
|
||||
{
|
||||
Listing lst(path);
|
||||
Entry tmp;
|
||||
return !lst.getNext(tmp);
|
||||
}
|
||||
|
||||
Listing::Listing( string const & dirName ): dirName( dirName )
|
||||
{
|
||||
dir = opendir( dirName.c_str() );
|
||||
|
|
3
dir.hh
3
dir.hh
|
@ -42,6 +42,9 @@ string getRealPath( string const & );
|
|||
/// Returns the directory part of the given path
|
||||
string getDirName( string const & );
|
||||
|
||||
/// Checkes whether directory is empty
|
||||
bool isDirEmpty( string const & );
|
||||
|
||||
/// A separator used to separate names in the path.
|
||||
inline char separator()
|
||||
{ return '/'; }
|
||||
|
|
12
zbackup.cc
12
zbackup.cc
|
@ -436,6 +436,18 @@ void ZRestore::gc()
|
|||
|
||||
checker.commit();
|
||||
|
||||
verbosePrintf( "Cleaning up...\n" );
|
||||
|
||||
string bundlesPath = getBundlesPath();
|
||||
Dir::Listing bundleLst( bundlesPath );
|
||||
while( bundleLst.getNext( entry ) )
|
||||
{
|
||||
const string dirPath = Dir::addPath( bundlesPath, entry.getFileName());
|
||||
if (entry.isDir() && Dir::isDirEmpty(dirPath)) {
|
||||
Dir::remove(dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
verbosePrintf( "Garbage collection complete\n" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue