Exemplo n.º 1
0
void CacheManager::cleanDirectory(const Directory& dir) const {
    LDEBUG("Cleaning directory '" << dir << "'");
    // First search for all subdirectories and call this function recursively on them
	std::vector<std::string> contents = dir.readDirectories();
	for (const auto& content : contents) {
        if (FileSys.directoryExists(content)) {
			cleanDirectory(content);
        }
	}
    // We get to this point in the recursion if either all subdirectories have been
    // deleted or there exists a file somewhere in the directory tree

	contents = dir.read();
    bool isEmpty = contents.empty();
#ifdef __APPLE__
    // Apple stores the .DS_Store directory in the directory which can be removed
    std::string dsStore = FileSys.pathByAppendingComponent(dir, ".DS_Store");
    isEmpty |= ((contents.size() == 1) && contents[0] == dsStore);
#endif
    // If this directory is empty, we can delete it
    if (isEmpty) {
        LDEBUG("Deleting directory '" << dir << "'");
		FileSys.deleteDirectory(dir);
    }
}
Exemplo n.º 2
0
Arquivo: fs.cpp Projeto: Gingar/port
bool safeCleanDirectory( const std::string &dir ) {
	try {
		cleanDirectory( dir );
		return true;
	} catch (...) {
		printf( "[util::fs] Cannot clean directory: %s\n", dir.c_str() );
		return false;
	}
}