/** * get the free space in the path's owner home folder * @param path * @return int */ private function getFreeSpace($path) { $storage = OC_Filesystem::getStorage($path); $owner = $storage->getOwner($path); $totalSpace = $this->getQuota($owner); if ($totalSpace == -1) { return -1; } $rootInfo = OC_FileCache::get('', "/" . $owner . "/files"); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared', "/" . $owner . "/files")) { $sharedInfo = OC_FileCache::get('/Shared', "/" . $owner . "/files"); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; return $totalSpace - $usedSpace; }
/** * get the storage object for a path * @param string path * @return OC_Filestorage */ public function getStorage($path) { if (!isset($this->storage_cache[$path])) { $this->storage_cache[$path] = OC_Filesystem::getStorage($this->getAbsolutePath($path)); } return $this->storage_cache[$path]; }
public function touch($path, $mtime = null) { if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->touch($this->getInternalPath($source), $mtime); } return false; }
/** * return the content of a file or return a zip file containning multiply files * * @param dir $dir * @param file $file ; seperated list of files to download * @param boolean $only_header ; boolean to only send header of the request */ public static function get($dir, $files, $only_header = false) { $xsendfile = false; if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { $xsendfile = true; } if (strpos($files, ';')) { $files = explode(';', $files); } if (is_array($files)) { self::validateZipDownload($dir, $files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); if ($xsendfile) { $filename = OC_Helper::tmpFileNoClean('.zip'); } else { $filename = OC_Helper::tmpFile('.zip'); } if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { exit("cannot open <{$filename}>\n"); } foreach ($files as $file) { $file = $dir . '/' . $file; if (OC_Filesystem::is_file($file)) { $tmpFile = OC_Filesystem::toTmpFile($file); self::$tmpFiles[] = $tmpFile; $zip->addFile($tmpFile, basename($file)); } elseif (OC_Filesystem::is_dir($file)) { self::zipAddDir($file, $zip); } } $zip->close(); set_time_limit($executionTime); } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) { self::validateZipDownload($dir, $files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); if ($xsendfile) { $filename = OC_Helper::tmpFileNoClean('.zip'); } else { $filename = OC_Helper::tmpFile('.zip'); } if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { exit("cannot open <{$filename}>\n"); } $file = $dir . '/' . $files; self::zipAddDir($file, $zip); $zip->close(); set_time_limit($executionTime); } else { $zip = false; $filename = $dir . '/' . $files; } OC_Util::obEnd(); if ($zip or OC_Filesystem::is_readable($filename)) { header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if ($zip) { ini_set('zlib.output_compression', 'off'); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); self::addSendfileHeader($filename); } else { header('Content-Type: ' . OC_Filesystem::getMimeType($filename)); $storage = OC_Filesystem::getStorage($filename); if ($storage instanceof OC_Filestorage_Local) { self::addSendfileHeader(OC_Filesystem::getLocalFile($filename)); } } } elseif ($zip or !OC_Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template('', '404', 'guest'); $tmpl->assign('file', $filename); $tmpl->printPage(); } else { header("HTTP/1.0 403 Forbidden"); die('403 Forbidden'); } if ($only_header) { if (!$zip) { header("Content-Length: " . OC_Filesystem::filesize($filename)); } return; } if ($zip) { $handle = fopen($filename, 'r'); if ($handle) { $chunkSize = 8 * 1024; // 1 MB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); flush(); } } if (!$xsendfile) { unlink($filename); } } else { OC_Filesystem::readfile($filename); } foreach (self::$tmpFiles as $tmpFile) { if (file_exists($tmpFile) and is_file($tmpFile)) { unlink($tmpFile); } } }
/** * get the storage object for a path * @param string path * @return OC_Filestorage */ public function getStorage($path) { return OC_Filesystem::getStorage($this->getAbsolutePath($path)); }
public function getLocalFile($path) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); return $storage->getLocalFile($this->getInternalPath($source)); } }