Ejemplo n.º 1
0
 public function getSize()
 {
     if ($this->size === null) {
         if ($this->isFile()) {
             $this->size = filesize($this->absolutePath);
         } else {
             $this->size = FileUtils::dirsize($this->absolutePath);
         }
     }
     return $this->size;
 }
Ejemplo n.º 2
0
 public function listEntries($absolutePath)
 {
     $writable = $this->isWritable();
     $sharable = $writable;
     $dirIsTorrent = $this->isTorrent($absolutePath);
     $dirDeletable = $writable && !$dirIsTorrent;
     $dirContainsTorrents = $this->containsTorrents($absolutePath);
     $name = basename($absolutePath);
     $entries = array();
     if (is_dir($absolutePath)) {
         $relativePath = $this->getRelativePath($absolutePath);
         $size = FileUtils::dirsize($absolutePath);
         $dir = opendir($absolutePath);
         while ($entry = readdir($dir)) {
             if ($entry != '.' && ($entry != '..' || $relativePath != '')) {
                 $entries[] = $entry;
             }
         }
         closedir($dir);
     } else {
         $size = filesize($absolutePath);
         $entries[] = basename($absolutePath);
         $absolutePath = dirname($absolutePath);
         $relativePath = $this->getRelativePath($absolutePath);
     }
     $result = array('name' => $name, 'size' => $size, 'files' => array());
     $absolutePath .= DIRECTORY_SEPARATOR;
     if ($relativePath != '') {
         $relativePath .= '/';
     }
     foreach ($entries as $entry) {
         $absoluteEntryPath = $absolutePath . $entry;
         if ($dirDeletable) {
             $cachable = $deletable = $dirContainsTorrents ? !$this->isTorrent($absoluteEntryPath) : true;
         } else {
             if ($dirIsTorrent) {
                 $cachable = false;
             } else {
                 $cachable = $dirContainsTorrents ? !$this->isTorrent($absoluteEntryPath) : true;
             }
             $deletable = false;
         }
         $result['files'][] = new File($absoluteEntryPath, $relativePath . $entry, $this->ownerId, $cachable, $deletable, $sharable);
     }
     usort($result['files'], function (File $a, File $b) {
         if (!$a->isFile() && $b->isFile()) {
             return -1;
         } elseif ($a->isFile() && !$b->isFile()) {
             return 1;
         }
         return strcmp($a->getName(), $b->getName());
     });
     return $result;
 }