skip *.pk3dir in root in DirectoryArchive::forEachFile

This commit is contained in:
Garux 2023-07-04 14:24:45 +06:00
parent 7396eef067
commit 3fb507e860
2 changed files with 3 additions and 8 deletions

View File

@ -90,7 +90,8 @@ public:
dirs.pop_back();
path.pop();
}
else if ( !string_equal( name, "." ) && !string_equal( name, ".." ) ) {
else if ( !string_equal( name, "." ) && !string_equal( name, ".." )
&& !( string_empty( root ) && string_equal_suffix_nocase( name, ".pk3dir" ) ) ) { //skip *.pk3dir in root, it is processed as DirectoryArchive
path.push_filename( name );
bool is_directory = file_is_directory( path.c_str() );

View File

@ -1183,12 +1183,11 @@ class ModelPaths_ArchiveVisitor : public Archive::Visitor
ModelFS& m_modelFS;
public:
const ModelFoldersMap& m_modelFoldersMap;
bool m_avoid_pk3dir;
ModelPaths_ArchiveVisitor( const StringSetWithLambda& modelExtensions, ModelFS& modelFS, const ModelFoldersMap& modelFoldersMap )
: m_modelExtensions( modelExtensions ), m_modelFS( modelFS ), m_modelFoldersMap( modelFoldersMap ){
}
void visit( const char* name ) override {
if( m_modelExtensions.count( path_get_extension( name ) ) && ( !m_avoid_pk3dir || !string_in_string_nocase( name, ".pk3dir/" ) ) ){
if( m_modelExtensions.count( path_get_extension( name ) ) ){
m_modelFS.insert( name );
//% globalOutputStream() << name << " name\n";
}
@ -1200,11 +1199,6 @@ void ModelPaths_addFromArchive( ModelPaths_ArchiveVisitor& visitor, const char *
Archive *archive = GlobalFileSystem().getArchive( archiveName, false );
if ( archive != nullptr ) {
for( const auto& folder : visitor.m_modelFoldersMap ){
/* should better avoid .pk3dir traversal right in archive implementation for normal folders */
visitor.m_avoid_pk3dir = string_empty( folder.first.c_str() ) // root
&& folder.second > 1 // deep nuff
&& string_equal_suffix( archiveName, "/" ) // normal folder, not archive
&& !string_equal_suffix_nocase( archiveName, ".pk3dir/" ); // not .pk3dir
archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, folder.second ), folder.first.c_str() );
}
}