Removing empty directories in bundles after performing garbage collection

Signed-off-by: Gleb Golubitsky <sectoid@gnolltech.org>
master
Gleb Golubitsky 2014-11-25 15:17:07 +02:00
parent 3522786202
commit 3747a3e5c4
3 changed files with 22 additions and 0 deletions

7
dir.cc
View File

@ -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
View File

@ -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 '/'; }

View File

@ -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" );
}