Code style
This commit is contained in:
parent
5474fea1f6
commit
8a838e0e03
|
@ -14,40 +14,49 @@ if (\OC_Util::runningOnWindows()) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for local filestore, we only have to map the paths
|
* for local filestore, we only have to map the paths
|
||||||
*/
|
*/
|
||||||
class Local extends \OC\Files\Storage\Common{
|
class Local extends \OC\Files\Storage\Common {
|
||||||
protected $datadir;
|
protected $datadir;
|
||||||
|
|
||||||
public function __construct($arguments) {
|
public function __construct($arguments) {
|
||||||
$this->datadir=$arguments['datadir'];
|
$this->datadir = $arguments['datadir'];
|
||||||
if(substr($this->datadir, -1)!=='/') {
|
if (substr($this->datadir, -1) !== '/') {
|
||||||
$this->datadir.='/';
|
$this->datadir .= '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
}
|
}
|
||||||
public function getId(){
|
|
||||||
return 'local::'.$this->datadir;
|
public function getId() {
|
||||||
|
return 'local::' . $this->datadir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mkdir($path) {
|
public function mkdir($path) {
|
||||||
return @mkdir($this->datadir.$path);
|
return @mkdir($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rmdir($path) {
|
public function rmdir($path) {
|
||||||
return @rmdir($this->datadir.$path);
|
return @rmdir($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function opendir($path) {
|
public function opendir($path) {
|
||||||
return opendir($this->datadir.$path);
|
return opendir($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_dir($path) {
|
public function is_dir($path) {
|
||||||
if(substr($path, -1)=='/') {
|
if (substr($path, -1) == '/') {
|
||||||
$path=substr($path, 0, -1);
|
$path = substr($path, 0, -1);
|
||||||
}
|
}
|
||||||
return is_dir($this->datadir.$path);
|
return is_dir($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_file($path) {
|
public function is_file($path) {
|
||||||
return is_file($this->datadir.$path);
|
return is_file($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stat($path) {
|
public function stat($path) {
|
||||||
$fullPath = $this->datadir . $path;
|
$fullPath = $this->datadir . $path;
|
||||||
$statResult = stat($fullPath);
|
$statResult = stat($fullPath);
|
||||||
|
@ -59,17 +68,19 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
}
|
}
|
||||||
return $statResult;
|
return $statResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filetype($path) {
|
public function filetype($path) {
|
||||||
$filetype=filetype($this->datadir.$path);
|
$filetype = filetype($this->datadir . $path);
|
||||||
if($filetype=='link') {
|
if ($filetype == 'link') {
|
||||||
$filetype=filetype(realpath($this->datadir.$path));
|
$filetype = filetype(realpath($this->datadir . $path));
|
||||||
}
|
}
|
||||||
return $filetype;
|
return $filetype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filesize($path) {
|
public function filesize($path) {
|
||||||
if($this->is_dir($path)) {
|
if ($this->is_dir($path)) {
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
} else {
|
||||||
$fullPath = $this->datadir . $path;
|
$fullPath = $this->datadir . $path;
|
||||||
$fileSize = filesize($fullPath);
|
$fileSize = filesize($fullPath);
|
||||||
if ($fileSize < 0) {
|
if ($fileSize < 0) {
|
||||||
|
@ -79,72 +90,83 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
return $fileSize;
|
return $fileSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isReadable($path) {
|
public function isReadable($path) {
|
||||||
return is_readable($this->datadir.$path);
|
return is_readable($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUpdatable($path) {
|
public function isUpdatable($path) {
|
||||||
return is_writable($this->datadir.$path);
|
return is_writable($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function file_exists($path) {
|
public function file_exists($path) {
|
||||||
return file_exists($this->datadir.$path);
|
return file_exists($this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filemtime($path) {
|
public function filemtime($path) {
|
||||||
return filemtime($this->datadir.$path);
|
return filemtime($this->datadir . $path);
|
||||||
}
|
}
|
||||||
public function touch($path, $mtime=null) {
|
|
||||||
|
public function touch($path, $mtime = null) {
|
||||||
// sets the modification time of the file to the given value.
|
// sets the modification time of the file to the given value.
|
||||||
// If mtime is nil the current time is set.
|
// If mtime is nil the current time is set.
|
||||||
// note that the access time of the file always changes to the current time.
|
// note that the access time of the file always changes to the current time.
|
||||||
if($this->file_exists($path) and !$this->isUpdatable($path)) {
|
if ($this->file_exists($path) and !$this->isUpdatable($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!is_null($mtime)) {
|
if (!is_null($mtime)) {
|
||||||
$result=touch( $this->datadir.$path, $mtime );
|
$result = touch($this->datadir . $path, $mtime);
|
||||||
}else{
|
} else {
|
||||||
$result=touch( $this->datadir.$path);
|
$result = touch($this->datadir . $path);
|
||||||
}
|
}
|
||||||
if( $result ) {
|
if ($result) {
|
||||||
clearstatcache( true, $this->datadir.$path );
|
clearstatcache(true, $this->datadir . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function file_get_contents($path) {
|
public function file_get_contents($path) {
|
||||||
return file_get_contents($this->datadir.$path);
|
return file_get_contents($this->datadir . $path);
|
||||||
}
|
}
|
||||||
public function file_put_contents($path, $data) {//trigger_error("$path = ".var_export($path, 1));
|
|
||||||
return file_put_contents($this->datadir.$path, $data);
|
public function file_put_contents($path, $data) { //trigger_error("$path = ".var_export($path, 1));
|
||||||
|
return file_put_contents($this->datadir . $path, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unlink($path) {
|
public function unlink($path) {
|
||||||
return $this->delTree($path);
|
return $this->delTree($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rename($path1, $path2) {
|
public function rename($path1, $path2) {
|
||||||
if (!$this->isUpdatable($path1)) {
|
if (!$this->isUpdatable($path1)) {
|
||||||
\OC_Log::write('core', 'unable to rename, file is not writable : '.$path1, \OC_Log::ERROR);
|
\OC_Log::write('core', 'unable to rename, file is not writable : ' . $path1, \OC_Log::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(! $this->file_exists($path1)) {
|
if (!$this->file_exists($path1)) {
|
||||||
\OC_Log::write('core', 'unable to rename, file does not exists : '.$path1, \OC_Log::ERROR);
|
\OC_Log::write('core', 'unable to rename, file does not exists : ' . $path1, \OC_Log::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($return=rename($this->datadir.$path1, $this->datadir.$path2)) {
|
if ($return = rename($this->datadir . $path1, $this->datadir . $path2)) {
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function copy($path1, $path2) {
|
public function copy($path1, $path2) {
|
||||||
if($this->is_dir($path2)) {
|
if ($this->is_dir($path2)) {
|
||||||
if(!$this->file_exists($path2)) {
|
if (!$this->file_exists($path2)) {
|
||||||
$this->mkdir($path2);
|
$this->mkdir($path2);
|
||||||
}
|
}
|
||||||
$source=substr($path1, strrpos($path1, '/')+1);
|
$source = substr($path1, strrpos($path1, '/') + 1);
|
||||||
$path2.=$source;
|
$path2 .= $source;
|
||||||
}
|
}
|
||||||
return copy($this->datadir.$path1, $this->datadir.$path2);
|
return copy($this->datadir . $path1, $this->datadir . $path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fopen($path, $mode) {
|
public function fopen($path, $mode) {
|
||||||
if($return=fopen($this->datadir.$path, $mode)) {
|
if ($return = fopen($this->datadir . $path, $mode)) {
|
||||||
switch($mode) {
|
switch ($mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
break;
|
break;
|
||||||
case 'r+':
|
case 'r+':
|
||||||
|
@ -162,30 +184,30 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMimeType($path) {
|
public function getMimeType($path) {
|
||||||
if($this->isReadable($path)) {
|
if ($this->isReadable($path)) {
|
||||||
return \OC_Helper::getMimeType($this->datadir . $path);
|
return \OC_Helper::getMimeType($this->datadir . $path);
|
||||||
}else{
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function delTree($dir) {
|
private function delTree($dir) {
|
||||||
$dirRelative=$dir;
|
$dirRelative = $dir;
|
||||||
$dir=$this->datadir.$dir;
|
$dir = $this->datadir . $dir;
|
||||||
if (!file_exists($dir)) return true;
|
if (!file_exists($dir)) return true;
|
||||||
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
|
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
|
||||||
foreach (scandir($dir) as $item) {
|
foreach (scandir($dir) as $item) {
|
||||||
if ($item == '.' || $item == '..') continue;
|
if ($item == '.' || $item == '..') continue;
|
||||||
if(is_file($dir.'/'.$item)) {
|
if (is_file($dir . '/' . $item)) {
|
||||||
if(unlink($dir.'/'.$item)) {
|
if (unlink($dir . '/' . $item)) {
|
||||||
}
|
}
|
||||||
}elseif(is_dir($dir.'/'.$item)) {
|
} elseif (is_dir($dir . '/' . $item)) {
|
||||||
if (!$this->delTree($dirRelative. "/" . $item)) {
|
if (!$this->delTree($dirRelative . "/" . $item)) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($return=rmdir($dir)) {
|
if ($return = rmdir($dir)) {
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -209,20 +231,20 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
\OC_Log::write('core',
|
\OC_Log::write('core',
|
||||||
'Unable to determine file size of "'.$fullPath.'". Unknown OS: '.$name,
|
'Unable to determine file size of "' . $fullPath . '". Unknown OS: ' . $name,
|
||||||
\OC_Log::ERROR);
|
\OC_Log::ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hash($path, $type, $raw=false) {
|
public function hash($path, $type, $raw = false) {
|
||||||
return hash_file($type, $this->datadir.$path, $raw);
|
return hash_file($type, $this->datadir . $path, $raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function free_space($path) {
|
public function free_space($path) {
|
||||||
$space = @disk_free_space($this->datadir.$path);
|
$space = @disk_free_space($this->datadir . $path);
|
||||||
if($space === false){
|
if ($space === false) {
|
||||||
return \OC\Files\FREE_SPACE_UNKNOWN;
|
return \OC\Files\FREE_SPACE_UNKNOWN;
|
||||||
}
|
}
|
||||||
return $space;
|
return $space;
|
||||||
|
@ -231,22 +253,24 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
public function search($query) {
|
public function search($query) {
|
||||||
return $this->searchInDir($query);
|
return $this->searchInDir($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLocalFile($path) {
|
public function getLocalFile($path) {
|
||||||
return $this->datadir.$path;
|
return $this->datadir . $path;
|
||||||
}
|
|
||||||
public function getLocalFolder($path) {
|
|
||||||
return $this->datadir.$path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function searchInDir($query, $dir='') {
|
public function getLocalFolder($path) {
|
||||||
$files=array();
|
return $this->datadir . $path;
|
||||||
foreach (scandir($this->datadir.$dir) as $item) {
|
|
||||||
if ($item == '.' || $item == '..') continue;
|
|
||||||
if(strstr(strtolower($item), strtolower($query))!==false) {
|
|
||||||
$files[]=$dir.'/'.$item;
|
|
||||||
}
|
}
|
||||||
if(is_dir($this->datadir.$dir.'/'.$item)) {
|
|
||||||
$files=array_merge($files, $this->searchInDir($query, $dir.'/'.$item));
|
protected function searchInDir($query, $dir = '') {
|
||||||
|
$files = array();
|
||||||
|
foreach (scandir($this->datadir . $dir) as $item) {
|
||||||
|
if ($item == '.' || $item == '..') continue;
|
||||||
|
if (strstr(strtolower($item), strtolower($query)) !== false) {
|
||||||
|
$files[] = $dir . '/' . $item;
|
||||||
|
}
|
||||||
|
if (is_dir($this->datadir . $dir . '/' . $item)) {
|
||||||
|
$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $files;
|
return $files;
|
||||||
|
@ -254,12 +278,13 @@ class Local extends \OC\Files\Storage\Common{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if a file or folder has been updated since $time
|
* check if a file or folder has been updated since $time
|
||||||
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $time
|
* @param int $time
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasUpdated($path, $time) {
|
public function hasUpdated($path, $time) {
|
||||||
return $this->filemtime($path)>$time;
|
return $this->filemtime($path) > $time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue