static HRESULT DeleteEmptyDirectories( __in LEGACY_SYNC_PRODUCT_SESSION *pSyncProductSession ) { HRESULT hr = S_OK; const LEGACY_FILE *rgFiles = pSyncProductSession->product.rgFiles; const DWORD cFiles = pSyncProductSession->product.cFiles; LPWSTR sczVirtualStorePath = NULL; for (DWORD i = 0; i < cFiles; ++i) { if (NULL == rgFiles[i].sczExpandedPath) { continue; } hr = DeleteEmptyDirectory(rgFiles[i].legacyFileType, rgFiles[i].sczExpandedPath); ExitOnFailure(hr, "Failed to scan for and delete empty directories for %ls", rgFiles[i].sczExpandedPath); // Delete the virtual store file as well hr = UtilConvertToVirtualStorePath(rgFiles[i].sczExpandedPath, &sczVirtualStorePath); ExitOnFailure(hr, "Failed to convert to virtualstore path: %ls", rgFiles[i].sczExpandedPath); hr = DeleteEmptyDirectory(rgFiles[i].legacyFileType, sczVirtualStorePath); ExitOnFailure(hr, "Falied to delete scan for and delete empty virtual store directories for %ls", sczVirtualStorePath); } LExit: ReleaseStr(sczVirtualStorePath); return hr; }
bool File::directoryDelete( Path const & p_path ) { struct FileFunction { void operator()( Path const & p_path ) { File::deleteFile( p_path ); } }; struct DirectoryFunction { bool operator()( Path const & p_path ) { bool result = TraverseDirectory( p_path, DirectoryFunction(), FileFunction() ); if ( result ) { result = DeleteEmptyDirectory( p_path ); } return result; } }; bool result = TraverseDirectory( p_path, DirectoryFunction(), FileFunction() ); if ( result ) { result = DeleteEmptyDirectory( p_path ); } return result; }
bool vsFile::DeleteDirectory( const vsString &filename ) { if ( DirectoryExists(filename) ) { vsArray<vsString> files; DirectoryContents(&files, filename); for ( int i = 0; i < files.ItemCount(); i++ ) { vsString ff = vsFormatString("%s/%s", filename.c_str(), files[i].c_str()); if ( vsFile::DirectoryExists( ff ) ) { // it's a directory; remove it! DeleteDirectory( ff ); } else { // it's a file, delete it. Delete( ff ); } } // I should now be empty, so delete me. return DeleteEmptyDirectory( filename ); } return false; }
bool operator()( Path const & p_path ) { bool result = TraverseDirectory( p_path, DirectoryFunction(), FileFunction() ); if ( result ) { result = DeleteEmptyDirectory( p_path ); } return result; }
// -------------------------------------------------------------------------- // // Function // Name: HousekeepStoreAccount::DeleteEmptyDirectories() // Purpose: Remove any empty directories which are also marked as deleted in their containing directory, // returning true if the opertaion was interrupted // Created: 15/12/03 // // -------------------------------------------------------------------------- bool HousekeepStoreAccount::DeleteEmptyDirectories(BackupStoreInfo& rBackupStoreInfo) { while(mEmptyDirectories.size() > 0) { std::vector<int64_t> toExamine; // Go through list for(std::vector<int64_t>::const_iterator i(mEmptyDirectories.begin()); i != mEmptyDirectories.end(); ++i) { #ifndef WIN32 if((--mCountUntilNextInterprocessMsgCheck) <= 0) { mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY; // Check for having to stop if(mpHousekeepingCallback && mpHousekeepingCallback->CheckForInterProcessMsg(mAccountID)) // include account ID here as the specified account is now locked { // Need to abort now return true; } } #endif // Do not delete the root directory if(*i == BACKUPSTORE_ROOT_DIRECTORY_ID) { continue; } DeleteEmptyDirectory(*i, toExamine, rBackupStoreInfo); } // Remove contents of empty directories mEmptyDirectories.clear(); // Swap in new, so it's examined next time round mEmptyDirectories.swap(toExamine); } // Not interrupted return false; }