/** * remove deleted files in $path from the cache * * @param string $path */ public function cleanFolder($path) { $cachedContent = $this->cache->getFolderContents($path); foreach ($cachedContent as $entry) { if (!$this->storage->file_exists($entry['path'])) { $this->cache->remove($entry['path']); } } }
public function stream_open($path, $mode, $options, &$opened_path) { $this->loadContext('ocencryption'); $this->position = 0; $this->cache = ''; $this->writeFlag = false; $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize($this->signed); if ($mode === 'w' || $mode === 'w+' || $mode === 'wb' || $mode === 'wb+' || $mode === 'r+' || $mode === 'rb+') { $this->readOnly = false; } else { $this->readOnly = true; } $sharePath = $this->fullPath; if (!$this->storage->file_exists($this->internalPath)) { $sharePath = dirname($sharePath); } $accessList = $this->file->getAccessList($sharePath); $this->newHeader = $this->encryptionModule->begin($this->fullPath, $this->uid, $mode, $this->header, $accessList); if ($mode === 'w' || $mode === 'w+' || $mode === 'wb' || $mode === 'wb+') { // We're writing a new file so start write counter with 0 bytes $this->unencryptedSize = 0; $this->writeHeader(); $this->headerSize = $this->util->getHeaderSize(); $this->size = $this->headerSize; } else { $this->skipHeader(); } return true; }
/** * Get file info from cache * * If the file is not in cached it will be scanned * If the file has changed on storage the cache will be updated * * @param \OC\Files\Storage\Storage $storage * @param string $internalPath * @param string $relativePath * @return array|bool */ private function getCacheEntry($storage, $internalPath, $relativePath) { $cache = $storage->getCache($internalPath); $data = $cache->get($internalPath); $watcher = $storage->getWatcher($internalPath); try { // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data if (!$data || $data['size'] === -1) { $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED); if (!$storage->file_exists($internalPath)) { $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); return false; } $scanner = $storage->getScanner($internalPath); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $data = $cache->get($internalPath); $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); } else { if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) { $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED); $watcher->update($internalPath, $data); $storage->getPropagator()->propagateChange($internalPath, time()); $data = $cache->get($internalPath); $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); } } } catch (LockedException $e) { // if the file is locked we just use the old cache info } return $data; }
/** * see http://php.net/manual/en/function.file_exists.php * * @param string $path * @return bool */ public function file_exists($path) { return $this->storage->file_exists($path); }
/** * Assembles the chunks into the file specified by the path. * Also triggers the relevant hooks and proxies. * * @param \OC\Files\Storage\Storage $storage * @param string $path target path relative to the storage * @param string $absolutePath * @return bool assembled file size or false if file could not be created * * @throws \OC\ServerNotAvailableException */ public function file_assemble($storage, $path, $absolutePath) { $data = ''; // use file_put_contents as method because that best matches what this function does if (\OC\Files\Filesystem::isValidPath($path)) { $exists = $storage->file_exists($path); $run = true; $hookPath = \OC\Files\Filesystem::getView()->getRelativePath($absolutePath); if (!$exists) { OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array(\OC\Files\Filesystem::signal_param_path => $hookPath, \OC\Files\Filesystem::signal_param_run => &$run)); } OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array(\OC\Files\Filesystem::signal_param_path => $hookPath, \OC\Files\Filesystem::signal_param_run => &$run)); if (!$run) { return false; } $target = $storage->fopen($path, 'w'); if ($target) { $count = $this->assemble($target); fclose($target); if (!$exists) { OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array(\OC\Files\Filesystem::signal_param_path => $hookPath)); } OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array(\OC\Files\Filesystem::signal_param_path => $hookPath)); return $count > 0; } else { return false; } } return false; }