/** * propagate the registered changes to their parent folders * * @param int $time (optional) the mtime to set for the folders, if not set the current time is used */ public function propagateChanges($time = null) { $changes = $this->getChanges(); $this->changedFiles = []; if (!$time) { $time = time(); } foreach ($changes as $change) { /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ $absolutePath = $this->view->getAbsolutePath($change); $mount = $this->view->getMount($change); $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($absolutePath); if ($storage) { $propagator = $storage->getPropagator(); $propagatedEntries = $propagator->propagateChange($internalPath, $time); foreach ($propagatedEntries as $entry) { $absolutePath = Filesystem::normalizePath($mount->getMountPoint() . '/' . $entry['path']); $relativePath = $this->view->getRelativePath($absolutePath); $this->emit('\\OC\\Files', 'propagate', [$relativePath, $entry]); } } } }
public function renameHook($params) { $path1 = $params['oldpath']; $path2 = $params['newpath']; $fullPath1 = $this->baseView->getAbsolutePath($path1); $fullPath2 = $this->baseView->getAbsolutePath($path2); $mount1 = $this->baseView->getMount($path1); $mount2 = $this->baseView->getMount($path2); if ($mount1 instanceof SharedMount and $mount1->getInternalPath($fullPath1) !== '') { $this->propagateForOwner($mount1->getShare(), $mount1->getInternalPath($fullPath1), $mount1->getOwnerPropagator()); } if ($mount1 !== $mount2 and $mount2 instanceof SharedMount and $mount2->getInternalPath($fullPath2) !== '') { $this->propagateForOwner($mount2->getShare(), $mount2->getInternalPath($fullPath2), $mount2->getOwnerPropagator()); } }
public function testPropagateCrossStorage() { $storage = new Temporary(); $this->view->mkdir('/foo'); Filesystem::mount($storage, [], $this->view->getAbsolutePath('/foo/submount')); $this->view->mkdir('/foo/submount/bar'); $this->view->file_put_contents('/foo/submount/bar/sad.txt', 'qwerty'); $oldInfo1 = $this->view->getFileInfo('/'); $oldInfo2 = $this->view->getFileInfo('/foo'); $oldInfo3 = $this->view->getFileInfo('/foo/submount'); $oldInfo4 = $this->view->getFileInfo('/foo/submount/bar'); $time = time() + 50; $this->propagator->addChange('/foo/submount/bar/sad.txt'); $this->propagator->propagateChanges($time); $newInfo1 = $this->view->getFileInfo('/'); $newInfo2 = $this->view->getFileInfo('/foo'); $newInfo3 = $this->view->getFileInfo('/foo/submount'); $newInfo4 = $this->view->getFileInfo('/foo/submount/bar'); $this->assertEquals($newInfo1->getMTime(), $time); $this->assertEquals($newInfo2->getMTime(), $time); $this->assertEquals($newInfo3->getMTime(), $time); $this->assertEquals($newInfo4->getMTime(), $time); $this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag()); $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag()); $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag()); $this->assertNotSame($oldInfo4->getEtag(), $newInfo3->getEtag()); }
/** * Moves a file from one location to another * * @param string $sourcePath The path to the file which should be moved * @param string $destinationPath The full destination path, so not just the destination parent node * @throws \Sabre\DAV\Exception\BadRequest * @throws \Sabre\DAV\Exception\ServiceUnavailable * @throws \Sabre\DAV\Exception\Forbidden * @return int */ public function move($sourcePath, $destinationPath) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } $targetNodeExists = $this->nodeExists($destinationPath); $sourceNode = $this->getNodeForPath($sourcePath); if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) { throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists'); } list($sourceDir, ) = \Sabre\HTTP\URLUtil::splitPath($sourcePath); list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destinationPath); $isMovableMount = false; $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath)); $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); if ($sourceMount instanceof MoveableMount && $internalPath === '') { $isMovableMount = true; } try { $sameFolder = $sourceDir === $destinationDir; // if we're overwriting or same folder if ($targetNodeExists || $sameFolder) { // note that renaming a share mount point is always allowed if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } } else { if (!$this->fileView->isCreatable($destinationDir)) { throw new \Sabre\DAV\Exception\Forbidden(); } } if (!$sameFolder) { // moving to a different folder, source will be gone, like a deletion // note that moving a share mount point is always allowed if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } } $fileName = basename($destinationPath); try { $this->fileView->verifyPath($destinationDir, $fileName); } catch (\OCP\Files\InvalidPathException $ex) { throw new InvalidPath($ex->getMessage()); } $renameOkay = $this->fileView->rename($sourcePath, $destinationPath); if (!$renameOkay) { throw new \Sabre\DAV\Exception\Forbidden(''); } } catch (StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } catch (ForbiddenException $ex) { throw new Forbidden($ex->getMessage(), $ex->getRetry()); } catch (LockedException $e) { throw new FileLocked($e->getMessage(), $e->getCode(), $e); } $this->markDirty($sourceDir); $this->markDirty($destinationDir); }
/** * Moves a file from one location to another * * @param string $sourcePath The path to the file which should be moved * @param string $destinationPath The full destination path, so not just the destination parent node * @throws \Sabre\DAV\Exception\BadRequest * @throws \Sabre\DAV\Exception\ServiceUnavailable * @throws \Sabre\DAV\Exception\Forbidden * @return int */ public function move($sourcePath, $destinationPath) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } $targetNodeExists = $this->nodeExists($destinationPath); $sourceNode = $this->getNodeForPath($sourcePath); if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) { throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode . ', target exists'); } list($sourceDir, ) = \Sabre\DAV\URLUtil::splitPath($sourcePath); list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destinationPath); $isMovableMount = false; $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath)); $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); if ($sourceMount instanceof MoveableMount && $internalPath === '') { $isMovableMount = true; } try { $sameFolder = $sourceDir === $destinationDir; // if we're overwriting or same folder if ($targetNodeExists || $sameFolder) { // note that renaming a share mount point is always allowed if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } } else { if (!$this->fileView->isCreatable($destinationDir)) { throw new \Sabre\DAV\Exception\Forbidden(); } } if (!$sameFolder) { // moving to a different folder, source will be gone, like a deletion // note that moving a share mount point is always allowed if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } } $fileName = basename($destinationPath); if (!\OCP\Util::isValidFileName($fileName)) { throw new \Sabre\DAV\Exception\BadRequest(); } $renameOkay = $this->fileView->rename($sourcePath, $destinationPath); if (!$renameOkay) { throw new \Sabre\DAV\Exception\Forbidden(''); } } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } // update properties $query = \OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?'); $query->execute(array(\OC\Files\Filesystem::normalizePath($destinationPath), \OC_User::getUser(), \OC\Files\Filesystem::normalizePath($sourcePath))); $this->markDirty($sourceDir); $this->markDirty($destinationDir); }
/** * Moves a file from one location to another * * @param string $sourcePath The path to the file which should be moved * @param string $destinationPath The full destination path, so not just the destination parent node * @throws \Sabre\DAV\Exception\BadRequest * @throws \Sabre\DAV\Exception\ServiceUnavailable * @throws \Sabre\DAV\Exception\Forbidden * @return int */ public function move($sourcePath, $destinationPath) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } $sourceNode = $this->getNodeForPath($sourcePath); if ($sourceNode instanceof \Sabre\DAV\ICollection and $this->nodeExists($destinationPath)) { throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode . ', target exists'); } list($sourceDir, ) = \Sabre\DAV\URLUtil::splitPath($sourcePath); list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destinationPath); $isMovableMount = false; $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath)); $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); if ($sourceMount instanceof MoveableMount && $internalPath === '') { $isMovableMount = true; } try { // check update privileges if (!$this->fileView->isUpdatable($sourcePath) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } if ($sourceDir !== $destinationDir) { if (!$this->fileView->isCreatable($destinationDir)) { throw new \Sabre\DAV\Exception\Forbidden(); } if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) { throw new \Sabre\DAV\Exception\Forbidden(); } } $fileName = basename($destinationPath); if (!\OCP\Util::isValidFileName($fileName)) { throw new \Sabre\DAV\Exception\BadRequest(); } $renameOkay = $this->fileView->rename($sourcePath, $destinationPath); if (!$renameOkay) { throw new \Sabre\DAV\Exception\Forbidden(''); } } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } // update properties $query = \OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?'); $query->execute(array(\OC\Files\Filesystem::normalizePath($destinationPath), \OC_User::getUser(), \OC\Files\Filesystem::normalizePath($sourcePath))); $this->markDirty($sourceDir); $this->markDirty($destinationDir); }
/** * get the size from a given root folder * @param \OC\Files\View $view file view on the root folder * @return integer size of the folder */ private static function calculateSize($view) { $root = \OCP\Config::getSystemValue('datadirectory') . $view->getAbsolutePath(''); if (!file_exists($root)) { return 0; } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST); $size = 0; /** * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach * This bug is fixed in PHP 5.5.9 or before * See #8376 */ $iterator->rewind(); while ($iterator->valid()) { $path = $iterator->current(); $relpath = substr($path, strlen($root) - 1); if (!$view->is_dir($relpath)) { $size += $view->filesize($relpath); } $iterator->next(); } return $size; }
/** * extract the metadata from a file * * uses getid3 to extract metadata. * if possible also adds content (currently only for plain text files) * hint: use OC\Files\Filesystem::getFileInfo($path) to get metadata for the last param * * @author Jörn Dreyer <*****@*****.**> * * @param Zend_Search_Lucene_Document $doc to add the metadata to * @param string $path path of the file to extract metadata from * @param string $mimetype depending on the mimetype different extractions are performed * * @return void */ private static function extractMetadata(\Zend_Search_Lucene_Document $doc, $path, \OC\Files\View $view, $mimetype) { $file = $view->getLocalFile($path); if (is_dir($file)) { // Don't lose time analizing a directory for file-specific metadata return; } $getID3 = new \getID3(); $getID3->encoding = 'UTF-8'; $data = $getID3->analyze($file); // TODO index meta information from media files? //show me what you got /*foreach ($data as $key => $value) { Util::writeLog('search_lucene', 'getid3 extracted '.$key.': '.$value, Util::DEBUG); if (is_array($value)) { foreach ($value as $k => $v) { Util::writeLog('search_lucene', ' ' . $value .'-' .$k.': '.$v, Util::DEBUG); } } }*/ if ('application/pdf' === $mimetype) { try { $zendpdf = \Zend_Pdf::parse($view->file_get_contents($path)); //we currently only display the filename, so we only index metadata here if (isset($zendpdf->properties['Title'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title'])); } if (isset($zendpdf->properties['Author'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author'])); } if (isset($zendpdf->properties['Subject'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject'])); } if (isset($zendpdf->properties['Keywords'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords'])); } //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata() //do the content extraction $pdfParse = new \App_Search_Helper_PdfParser(); $body = $pdfParse->pdf2txt($zendpdf->render()); } catch (Exception $e) { Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR); } } if ($body != '') { $doc->addField(\Zend_Search_Lucene_Field::UnStored('body', $body)); } if (isset($data['error'])) { Util::writeLog('search_lucene', 'failed to extract meta information for ' . $view->getAbsolutePath($path) . ': ' . $data['error']['0'], Util::WARN); return; } }
protected function getPropagatorPath($path) { return $this->propagatorView->getRelativePath($this->view->getAbsolutePath($path)); }