Logo Search packages:      
Sourcecode: k4dirstat version File versions  Download package

void KLocalDirReadJob::startReading (  ) [protected, virtual]

Read the directory. Prior to this nothing happens.

Inherited and reimplemented from KDirReadJob.

Reimplemented from KDirStat::KDirReadJob.

Definition at line 123 of file kdirreadjob.cpp.

References KDirStat::KDirTree::addJob(), KDirStat::KDirReadJob::childAdded(), KDirStat::KDirTree::crossFileSystems(), KDirStat::KDirTree::deleteSubtree(), KDirStat::KFileInfo::device(), KDirStat::KDirReadJob::dir(), KDirStat::KExcludeRules::excludeRules(), KDirStat::KDirInfo::finalizeLocal(), KDirStat::KDirReadJob::finished(), KDirStat::KCacheReader::firstDir(), KDirStat::KDirInfo::insertChild(), KDirStat::KDirReadJobQueue::killAll(), KLocalDirReadJob(), KDirStat::KFileInfo::parent(), KDirStat::KCacheReadJob::reader(), KDirStat::KCacheReader::rewind(), KDirStat::KDirTree::sendFinalizeLocal(), KDirStat::KDirTree::sendProgressInfo(), KDirStat::KDirInfo::setExcluded(), KDirStat::KDirInfo::setMountPoint(), KDirStat::KDirInfo::setReadState(), stat(), and KDirStat::KFileInfo::url().

{
    struct dirent *     entry;
    struct stat         statInfo;
    QString       dirName            = _dir->url();
    QString       defaultCacheName = DEFAULT_CACHE_NAME.url();

    if ( ( _diskDir = opendir( dirName ) ) )
    {
      _tree->sendProgressInfo( dirName );
      _dir->setReadState( KDirReading );

      while ( ( entry = readdir( _diskDir ) ) )
      {
          QString entryName = entry->d_name;

          if ( entryName != "."  &&
             entryName != ".."   )
          {
            QString fullName = dirName + "/" + entryName;

            if ( lstat( fullName, &statInfo ) == 0 )  // lstat() OK
            {
                if ( S_ISDIR( statInfo.st_mode ) )    // directory child?
                {
                  KDirInfo *subDir = new KDirInfo( entryName, &statInfo, _tree, _dir );
                  _dir->insertChild( subDir );
                  childAdded( subDir );

                  if ( KExcludeRules::excludeRules()->match( fullName ) )
                  {
                      subDir->setExcluded();
                      subDir->setReadState( KDirOnRequestOnly );
                      _tree->sendFinalizeLocal( subDir );
                      subDir->finalizeLocal();
                  }
                  else // No exclude rule matched
                  {
                      if ( _dir->device() == subDir->device()     )     // normal case
                      {
                        _tree->addJob( new KLocalDirReadJob( _tree, subDir ) );
                      }
                      else    // The subdirectory we just found is a mount point.
                      {
                        // kdDebug() << "Found mount point " << subDir << endl;
                        subDir->setMountPoint();

                        if ( _tree->crossFileSystems() )
                        {
                            _tree->addJob( new KLocalDirReadJob( _tree, subDir ) );
                        }
                        else
                        {
                            subDir->setReadState( KDirOnRequestOnly );
                            _tree->sendFinalizeLocal( subDir );
                            subDir->finalizeLocal();
                        }
                      }
                  }
                }
                else          // non-directory child
                {
                  if ( entryName == defaultCacheName )      // .kdirstat.cache.gz found?
                  {
                      //
                      // Read content of this subdirectory from cache file
                      //

                      
                      KCacheReadJob * cacheReadJob = new KCacheReadJob( _tree, _dir->parent(), fullName );
                      Q_CHECK_PTR( cacheReadJob );
                      QString firstDirInCache = cacheReadJob->reader()->firstDir();

                      if ( firstDirInCache == dirName )     // Does this cache file match this directory?
                      {
                        kdDebug() << "Using cache file " << fullName << " for " << dirName << endl;

                        cacheReadJob->reader()->rewind();   // Read offset was moved by firstDir()
                        _tree->addJob( cacheReadJob );      // Job queue will assume ownership of cacheReadJob

                        //
                        // Clean up partially read directory content
                        //

                        KDirTree * tree = _tree;      // Copy data members to local variables:
                        KDirInfo * dir  = _dir;       // This object will be deleted soon by killAll()

                        _queue->killAll( dir );       // Will delete this job as well!
                        // All data members of this object are invalid from here on!

                        tree->deleteSubtree( dir );

                        return;
                      }
                      else
                      {
                        kdDebug() << "NOT using cache file " << fullName
                                << " with dir " << firstDirInCache
                                << " for " << dirName
                                << endl;

                        delete cacheReadJob;
                      }
                  }
                  else
                  {
                      KFileInfo *child = new KFileInfo( entryName, &statInfo, _tree, _dir );
                      _dir->insertChild( child );
                      childAdded( child );
                  }
                }
            }
            else              // lstat() error
            {
                kdWarning() << "lstat(" << fullName << ") failed: " << strerror( errno ) << endl;

                /*
                 * Not much we can do when lstat() didn't work; let's at
                 * least create an (almost empty) entry as a placeholder.
                 */
                KDirInfo *child = new KDirInfo( _tree, _dir, entry->d_name );
                child->setReadState( KDirError );
                _dir->insertChild( child );
                childAdded( child );
            }
          }
      }

      closedir( _diskDir );
      // kdDebug() << "Finished reading " << _dir << endl;
      _dir->setReadState( KDirFinished );
      _tree->sendFinalizeLocal( _dir );
      _dir->finalizeLocal();
    }
    else
    {
      _dir->setReadState( KDirError );
      _tree->sendFinalizeLocal( _dir );
      _dir->finalizeLocal();
      // kdWarning() << k_funcinfo << "opendir(" << dirName << ") failed" << endl;
      // opendir() doesn't set 'errno' according to POSIX  :-(
    }

    finished();
    // Don't add anything after finished() since this deletes this job!
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index