Merge pull request #1906 from owncloud/storage-stat-fail

Common storage: don't throw warning when a stat fails
This commit is contained in:
Bernhard Posselt 2013-02-26 00:44:42 -08:00
commit b987c76d16
1 changed files with 116 additions and 83 deletions

View File

@ -22,33 +22,45 @@ namespace OC\Files\Storage;
abstract class Common implements \OC\Files\Storage\Storage {
public function __construct($parameters) {}
public function __construct($parameters) {
}
public function is_dir($path) {
return $this->filetype($path) == 'dir';
}
public function is_file($path) {
return $this->filetype($path) == 'file';
}
public function filesize($path) {
if ($this->is_dir($path)) {
return 0; //by definition
} else {
$stat = $this->stat($path);
if (isset($stat['size'])) {
return $stat['size'];
} else {
return 0;
}
}
}
public function isCreatable($path) {
if ($this->is_dir($path) && $this->isUpdatable($path)) {
return true;
}
return false;
}
public function isDeletable($path) {
return $this->isUpdatable($path);
}
public function isSharable($path) {
return $this->isReadable($path);
}
public function getPermissions($path) {
$permissions = 0;
if ($this->isCreatable($path)) {
@ -68,10 +80,16 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
return $permissions;
}
public function filemtime($path) {
$stat = $this->stat($path);
if (isset($stat['mtime'])) {
return $stat['mtime'];
} else {
return 0;
}
}
public function file_get_contents($path) {
$handle = $this->fopen($path, "r");
if (!$handle) {
@ -83,10 +101,12 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
return fread($handle, $size);
}
public function file_put_contents($path, $data) {
$handle = $this->fopen($path, "w");
return fwrite($handle, $data);
}
public function rename($path1, $path2) {
if ($this->copy($path1, $path2)) {
return $this->unlink($path1);
@ -94,6 +114,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
return false;
}
}
public function copy($path1, $path2) {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
@ -114,7 +135,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
$directory = trim($directory, '/');
if (!$this->file_exists(\OCP\USER::getUser() . '/' . $directory)
|| !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) {
|| !$this->is_dir(\OCP\USER::getUser() . '/' . $directory)
) {
return false;
} elseif (!$this->isReadable(\OCP\USER::getUser() . '/' . $directory)) {
return false;
@ -140,6 +162,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
}
public function getMimeType($path) {
if (!$this->file_exists($path)) {
return false;
@ -163,18 +186,22 @@ abstract class Common implements \OC\Files\Storage\Storage {
unlink($tmpFile);
return $mime;
}
public function hash($type, $path, $raw = false) {
$tmpFile = $this->getLocalFile($path);
$hash = hash($type, $tmpFile, $raw);
unlink($tmpFile);
return $hash;
}
public function search($query) {
return $this->searchInDir($query);
}
public function getLocalFile($path) {
return $this->toTmpFile($path);
}
private function toTmpFile($path) { //no longer in the storage api, still useful here
$source = $this->fopen($path, 'r');
if (!$source) {
@ -190,11 +217,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
\OC_Helper::streamCopy($source, $target);
return $tmpFile;
}
public function getLocalFolder($path) {
$baseDir = \OC_Helper::tmpFolder();
$this->addLocalFolder($path, $baseDir);
return $baseDir;
}
private function addLocalFolder($path, $target) {
if ($dh = $this->opendir($path)) {
while ($file = readdir($dh)) {
@ -230,6 +259,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* check if a file or folder has been updated since $time
*
* @param string $path
* @param int $time
* @return bool
@ -256,6 +286,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* get the owner of a path
*
* @param string $path The path to get the owner
* @return string uid or false
*/
@ -282,6 +313,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* clean a path, i.e. remove all redundant '.' and '..'
* making sure that it can't point to higher than '/'
*
* @param $path The path to clean
* @return string cleaned path
*/
@ -304,6 +336,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* get the free space in the storage
*
* @param $path
* return int
*/