Ignore:
Timestamp:
07/02/15 11:07:42 (9 years ago)
Author:
Maciej Komosinski
Message:

ChainFileSystem? can merge Vopendir() results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/virtfile/virtfile.cpp

    r302 r410  
    189189        printf("ChainFileSystem::Vfopendir %s (chain=%p)\n",path,chain);
    190190#endif
    191         return (chain != NULL) ? chain->Vopendir(path) : NULL;
     191        if (chain==NULL) return internalopendir(path);
     192        return new Dir(string(path),this,chain);
    192193}
    193194
     
    206207        return (chain != NULL) ? chain->Vdirexists(path, is_writable) : false;
    207208}
     209
     210ChainFileSystem::Dir::~Dir()
     211{
     212if (dir) delete dir;
     213}
     214
     215dirent* ChainFileSystem::Dir::Vreaddir()
     216{
     217dirent *de;
     218  retry:
     219if (!dir)
     220        {
     221        if (first)
     222                {
     223                dir=first->internalopendir(path.c_str());
     224                first=NULL;
     225                }
     226        else if (second)
     227                {
     228                dir=second->Vopendir(path.c_str());
     229                second=NULL;
     230                }
     231        else
     232                return NULL;
     233        }
     234de=dir ? dir->Vreaddir() : NULL;
     235if (de==NULL)
     236        {if (dir) delete dir; dir=NULL; goto retry;}
     237
     238// no need to check for duplicates if no names are saved and scanning the last location (most common case)
     239if (! (duplicates.empty() && (first==NULL) && (second==NULL)) )
     240{
     241string s(de->d_name);
     242if (duplicates.find(s)==duplicates.end())
     243        duplicates.insert(s);
     244else
     245        goto retry;
     246}
     247
     248return de;
     249}
Note: See TracChangeset for help on using the changeset viewer.