Esempio n. 1
0
 /**
  * @dataProvider baseNameProvider
  */
 public function testBaseName($expected, $file)
 {
     $base = \OC_Util::basename($file);
     $this->assertEquals($expected, $base);
 }
Esempio n. 2
0
 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         // normalize file
         $file = $this->normalize($file);
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = \OC_Util::basename($file);
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->getNumericStorageId();
         $valuesPlaceholder = array_fill(0, count($queryParts), '?');
         $sql = 'INSERT INTO `*PREFIX*filecache` (' . implode(', ', $queryParts) . ')' . ' VALUES (' . implode(', ', $valuesPlaceholder) . ')';
         \OC_DB::executeAudited($sql, $params);
         return (int) \OC_DB::insertid('*PREFIX*filecache');
     }
 }
 public function rename($source, $target)
 {
     $source = $this->normalizePath($source);
     $target = $this->normalizePath($target);
     $stat1 = $this->stat($source);
     if (isset($stat1['mimetype']) && $stat1['mimetype'] === 'httpd/unix-directory') {
         $this->remove($target);
         $dir = $this->opendir($source);
         $this->mkdir($target);
         while ($file = readdir($dir)) {
             if (!Filesystem::isIgnoredDir($file)) {
                 if (!$this->rename($source . '/' . $file, $target . '/' . $file)) {
                     return false;
                 }
             }
         }
         closedir($dir);
         $this->remove($source);
         return true;
     } else {
         if (is_array($stat1)) {
             $parent = $this->stat(dirname($target));
             if (is_array($parent)) {
                 $this->remove($target);
                 $stat1['parent'] = $parent['fileid'];
                 $stat1['path'] = $target;
                 $stat1['path_hash'] = md5($target);
                 $stat1['name'] = \OC_Util::basename($target);
                 $stat1['mtime'] = time();
                 $stat1['etag'] = $this->getETag($target);
                 $this->getCache()->update($stat1['fileid'], $stat1);
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 4
0
 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  * @throws \RuntimeException
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         // normalize file
         $file = $this->normalize($file);
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = \OC_Util::basename($file);
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->getNumericStorageId();
         $queryParts = array_map(function ($item) {
             return trim($item, "`");
         }, $queryParts);
         $values = array_combine($queryParts, $params);
         if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, ['storage', 'path_hash'])) {
             return (int) $this->connection->lastInsertId('*PREFIX*filecache');
         }
         // The file was created in the mean time
         if (($id = $this->getId($file)) > -1) {
             $this->update($id, $data);
             return $id;
         } else {
             throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.');
         }
     }
 }
Esempio n. 5
0
	/**
	 * store meta data for a file or folder
	 *
	 * @param string $file
	 * @param array $data
	 *
	 * @return int file id
	 */
	public function put($file, array $data) {
		if (($id = $this->getId($file)) > -1) {
			$this->update($id, $data);
			return $id;
		} else {
			// normalize file
			$file = $this->normalize($file);

			if (isset($this->partial[$file])) { //add any saved partial data
				$data = array_merge($this->partial[$file], $data);
				unset($this->partial[$file]);
			}

			$requiredFields = array('size', 'mtime', 'mimetype');
			foreach ($requiredFields as $field) {
				if (!isset($data[$field])) { //data not complete save as partial and return
					$this->partial[$file] = $data;
					return -1;
				}
			}

			$data['path'] = $file;
			$data['parent'] = $this->getParentId($file);
			$data['name'] = \OC_Util::basename($file);

			list($queryParts, $params) = $this->buildParts($data);
			$queryParts[] = '`storage`';
			$params[] = $this->getNumericStorageId();

			$params = array_map(function($item) {
				return trim($item, "`");
			}, $params);
			$queryParts = array_map(function($item) {
				return trim($item, "`");
			}, $queryParts);
			$values = array_combine($queryParts, $params);
			if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values)) {
				return (int)\OC_DB::insertid('*PREFIX*filecache');
			}

			return $this->getId($file);
		}
	}
Esempio n. 6
0
             exit;
         }
     } else {
         // Check if item id is set in session
         if (!\OC::$server->getSession()->exists('public_link_authenticated') || \OC::$server->getSession()->get('public_link_authenticated') !== $linkItem['id']) {
             // Prompt for password
             OCP\Util::addStyle('files_sharing', 'authenticate');
             $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
             $tmpl->assign('URL', $url);
             $tmpl->printPage();
             exit;
         }
     }
 }
 $basePath = $path;
 $rootName = \OC_Util::basename($path);
 if (isset($_GET['path']) && \OC\Files\Filesystem::isReadable($basePath . $_GET['path'])) {
     $getPath = \OC\Files\Filesystem::normalizePath($_GET['path']);
     $path .= $getPath;
 } else {
     $getPath = '';
 }
 $dir = dirname($path);
 $file = basename($path);
 // Download the file
 if (isset($_GET['download'])) {
     if (!\OCP\App::isEnabled('files_encryption')) {
         // encryption app requires the session to store the keys in
         \OC::$server->getSession()->close();
     }
     if (isset($_GET['files'])) {