public function filetype($path) { $path = $this->normalizePath($path); if ($this->doesObjectExist($path)) { $object = $this->container->getPartialObject($path); return $this->getFileType($object); } }
public function filetype($path) { $path = $this->normalizePath($path); if ($this->doesObjectExist($path)) { $object = $this->container->getPartialObject($path); if ($object->getContentType() == 'application/directory') { return 'dir'; } elseif ($object->getContentType() == 'httpd/unix-directory') { return 'dir'; } else { return 'file'; } } }
public function copy($path1, $path2) { $path1 = $this->normalizePath($path1); $path2 = $this->normalizePath($path2); $fileType = $this->filetype($path1); if ($fileType === 'file') { // make way $this->unlink($path2); try { $source = $this->container->getPartialObject($path1); $source->copy($this->bucket . '/' . $path2); } catch (ClientErrorResponseException $e) { \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); return false; } } else { if ($fileType === 'dir') { // make way $this->unlink($path2); try { $source = $this->container->getPartialObject($path1 . '/'); $source->copy($this->bucket . '/' . $path2 . '/'); } catch (ClientErrorResponseException $e) { \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); return false; } $dh = $this->opendir($path1); while ($file = readdir($dh)) { if ($file === '.' || $file === '..') { continue; } $source = $path1 . '/' . $file; $target = $path2 . '/' . $file; $this->copy($source, $target); } } else { //file does not exist return false; } } return true; }
/** * Get the metadata of an object. * * @param string $path * * @return DataObject */ protected function getPartialObject($path) { $location = $this->applyPathPrefix($path); return $this->container->getPartialObject($location); }
/** * @param BaseContainer $container Parent container * @param $name Name of object */ public function __construct(RendererInterface $renderer, BaseContainer $container, $name) { $this->renderer = $renderer; $this->dataObject = $container->getPartialObject($name); }