Пример #1
0
 /**
  * Steps the files scanning of the current directory
  *
  * @return  boolean  True on success, false on fatal error
  */
 protected function scanFiles()
 {
     $engine = Factory::getScanEngine();
     list($root, $translated_root, $dir) = $this->getCleanDirectoryComponents();
     // Get a filters instance
     $filters = Factory::getFilters();
     if (is_null($this->getFiles_position)) {
         Factory::getLog()->log(LogLevel::INFO, "Scanning files of " . $this->current_directory);
         $this->processed_files_counter = 0;
     } else {
         Factory::getLog()->log(LogLevel::INFO, "Resuming scanning files of " . $this->current_directory);
     }
     // Get file listing
     $fileList = $engine->getFiles($this->current_directory, $this->getFiles_position);
     // Error propagation
     $this->propagateFromObject($engine);
     // If the list contains "too many" items, please break this step!
     if (Factory::getConfiguration()->get('volatile.breakflag', false)) {
         // Log the step break decision, for debugging reasons
         Factory::getLog()->log(LogLevel::INFO, "Large directory " . $this->current_directory . " while scanning for files; I will resume scanning in next step.");
         // Return immediately, marking that we are not done yet!
         return true;
     }
     // Error control
     if ($this->getError()) {
         return false;
     }
     // Do I have an unreadable directory?
     if ($fileList === false) {
         $this->setWarning('Unreadable directory ' . $this->current_directory);
         $this->done_file_scanning = true;
     } else {
         if (is_array($fileList) && !empty($fileList)) {
             // Add required trailing slash to $dir
             if (!empty($dir)) {
                 $dir .= '/';
             }
             // Scan all directory entries
             foreach ($fileList as $fileName) {
                 $check = $dir . basename($fileName);
                 if (_AKEEBA_IS_WINDOWS) {
                     $check = Factory::getFilesystemTools()->TranslateWinPath($check);
                 }
                 // Do I need this? $dir contains a path relative to the root anyway...
                 $check = ltrim(str_replace($translated_root, '', $check), '/');
                 $byFilter = '';
                 $skipThisFile = $filters->isFilteredExtended($check, $root, 'file', 'all', $byFilter);
                 if ($skipThisFile) {
                     Factory::getLog()->log(LogLevel::INFO, "Skipping file {$fileName} (filter: {$byFilter})");
                 } else {
                     $this->file_list[] = $fileName;
                     $this->processed_files_counter++;
                     $this->progressAddFile();
                 }
             }
         }
     }
     // If the scanner engine nullified the next position we are done
     // scanning for files
     if (is_null($this->getFiles_position)) {
         $this->done_file_scanning = true;
     }
     // If the directory was genuinely empty we will have to add an empty
     // directory entry in the archive, otherwise this directory will never
     // be restored.
     if ($this->done_file_scanning && $this->processed_files_counter == 0) {
         Factory::getLog()->log(LogLevel::INFO, "Empty directory " . $this->current_directory);
         $archiver = Factory::getArchiverEngine();
         if ($this->current_directory != $this->remove_path_prefix) {
             $archiver->addFile($this->current_directory, $this->remove_path_prefix, $this->path_prefix);
         }
         // Error propagation
         $this->propagateFromObject($archiver);
         // Check for errors
         if ($this->getError()) {
             return false;
         }
         unset($archiver);
     }
     return true;
 }