Пример #1
0
 /**
  * update the cache according to changes in the folder
  * @param string path
  * @param string root (optional)
  */
 public static function updateFolder($path, $root = false)
 {
     if ($root === false) {
         $view = OC_Filesystem::getView();
     } else {
         $view = new OC_FilesystemView($root);
     }
     $dh = $view->opendir($path . '/');
     if ($dh) {
         //check for changed/new files
         while (($filename = readdir($dh)) !== false) {
             if ($filename != '.' and $filename != '..' and $filename != '') {
                 $file = $path . '/' . $filename;
                 $isDir = $view->is_dir($file);
                 if (self::hasUpdated($file, $root, $isDir)) {
                     if ($isDir) {
                         self::updateFolder($file, $root);
                     } elseif ($root === false) {
                         //filesystem hooks are only valid for the default root
                         OC_Hook::emit('OC_Filesystem', 'post_write', array('path' => $file));
                     } else {
                         self::update($file, $root);
                     }
                 }
             }
         }
     }
     self::cleanFolder($path, $root);
     //update the folder last, so we can calculate the size correctly
     if ($root === false) {
         //filesystem hooks are only valid for the default root
         OC_Hook::emit('OC_Filesystem', 'post_write', array('path' => $path));
     } else {
         self::update($path, $root);
     }
 }
Пример #2
0
 /**
  * recursively scan the filesystem and fill the cache
  * @param string $path
  * @param OC_EventSource $enventSource (optional)
  * @param int count (optional)
  * @param string root (optional)
  */
 public static function scan($path, $eventSource = false, &$count = 0, $root = false)
 {
     if ($eventSource) {
         $eventSource->send('scanning', array('file' => $path, 'count' => $count));
     }
     $lastSend = $count;
     // NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
     if (substr($path, 0, 7) == '/Shared') {
         return;
     }
     if ($root === false) {
         $view = OC_Filesystem::getView();
     } else {
         $view = new OC_FilesystemView($root);
     }
     self::scanFile($path, $root);
     $dh = $view->opendir($path . '/');
     $totalSize = 0;
     if ($dh) {
         while (($filename = readdir($dh)) !== false) {
             if ($filename != '.' and $filename != '..') {
                 $file = $path . '/' . $filename;
                 if ($view->is_dir($file . '/')) {
                     self::scan($file, $eventSource, $count, $root);
                 } else {
                     $totalSize += self::scanFile($file, $root);
                     $count++;
                     if ($count > $lastSend + 25 and $eventSource) {
                         $lastSend = $count;
                         $eventSource->send('scanning', array('file' => $path, 'count' => $count));
                     }
                 }
             }
         }
     }
     OC_FileCache_Update::cleanFolder($path, $root);
     self::increaseSize($path, $totalSize, $root);
 }