Skip to content

Commit

Permalink
Merge pull request #12462 from owncloud/issue/12460-localstorage-buil…
Browse files Browse the repository at this point in the history
…dpath

Introduce buildPath() in Storage\Local to reduce the difference to MappedLocal
  • Loading branch information
Vincent Petry committed Nov 27, 2014
2 parents a217278 + 4f1bbc4 commit e733d32
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 63 deletions.
77 changes: 46 additions & 31 deletions lib/private/files/storage/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getId() {
}

public function mkdir($path) {
return @mkdir($this->datadir . $path, 0777, true);
return @mkdir($this->getSourcePath($path), 0777, true);
}

public function rmdir($path) {
Expand All @@ -44,7 +44,7 @@ public function rmdir($path) {
}
try {
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->datadir . $path),
new \RecursiveDirectoryIterator($this->getSourcePath($path)),
\RecursiveIteratorIterator::CHILD_FIRST
);
/**
Expand All @@ -68,30 +68,30 @@ public function rmdir($path) {
}
$it->next();
}
return rmdir($this->datadir . $path);
return rmdir($this->getSourcePath($path));
} catch (\UnexpectedValueException $e) {
return false;
}
}

public function opendir($path) {
return opendir($this->datadir . $path);
return opendir($this->getSourcePath($path));
}

public function is_dir($path) {
if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
}
return is_dir($this->datadir . $path);
return is_dir($this->getSourcePath($path));
}

public function is_file($path) {
return is_file($this->datadir . $path);
return is_file($this->getSourcePath($path));
}

public function stat($path) {
clearstatcache();
$fullPath = $this->datadir . $path;
$fullPath = $this->getSourcePath($path);
$statResult = stat($fullPath);
if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) {
$filesize = $this->filesize($path);
Expand All @@ -102,9 +102,9 @@ public function stat($path) {
}

public function filetype($path) {
$filetype = filetype($this->datadir . $path);
$filetype = filetype($this->getSourcePath($path));
if ($filetype == 'link') {
$filetype = filetype(realpath($this->datadir . $path));
$filetype = filetype(realpath($this->getSourcePath($path)));
}
return $filetype;
}
Expand All @@ -113,7 +113,7 @@ public function filesize($path) {
if ($this->is_dir($path)) {
return 0;
}
$fullPath = $this->datadir . $path;
$fullPath = $this->getSourcePath($path);
if (PHP_INT_SIZE === 4) {
$helper = new \OC\LargeFileHelper;
return $helper->getFilesize($fullPath);
Expand All @@ -122,19 +122,19 @@ public function filesize($path) {
}

public function isReadable($path) {
return is_readable($this->datadir . $path);
return is_readable($this->getSourcePath($path));
}

public function isUpdatable($path) {
return is_writable($this->datadir . $path);
return is_writable($this->getSourcePath($path));
}

public function file_exists($path) {
return file_exists($this->datadir . $path);
return file_exists($this->getSourcePath($path));
}

public function filemtime($path) {
return filemtime($this->datadir . $path);
return filemtime($this->getSourcePath($path));
}

public function touch($path, $mtime = null) {
Expand All @@ -145,30 +145,30 @@ public function touch($path, $mtime = null) {
return false;
}
if (!is_null($mtime)) {
$result = touch($this->datadir . $path, $mtime);
$result = touch($this->getSourcePath($path), $mtime);
} else {
$result = touch($this->datadir . $path);
$result = touch($this->getSourcePath($path));
}
if ($result) {
clearstatcache(true, $this->datadir . $path);
clearstatcache(true, $this->getSourcePath($path));
}

return $result;
}

public function file_get_contents($path) {
return file_get_contents($this->datadir . $path);
return file_get_contents($this->getSourcePath($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) {
return file_put_contents($this->getSourcePath($path), $data);
}

public function unlink($path) {
if ($this->is_dir($path)) {
return $this->rmdir($path);
} else if ($this->is_file($path)) {
return unlink($this->datadir . $path);
return unlink($this->getSourcePath($path));
} else {
return false;
}
Expand Down Expand Up @@ -200,27 +200,27 @@ public function rename($path1, $path2) {
$this->unlink($path2);
}

return rename($this->datadir . $path1, $this->datadir . $path2);
return rename($this->getSourcePath($path1), $this->getSourcePath($path2));
}

public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
return parent::copy($path1, $path2);
} else {
return copy($this->datadir . $path1, $this->datadir . $path2);
return copy($this->getSourcePath($path1), $this->getSourcePath($path2));
}
}

public function fopen($path, $mode) {
return fopen($this->datadir . $path, $mode);
return fopen($this->getSourcePath($path), $mode);
}

public function hash($type, $path, $raw = false) {
return hash_file($type, $this->datadir . $path, $raw);
return hash_file($type, $this->getSourcePath($path), $raw);
}

public function free_space($path) {
$space = @disk_free_space($this->datadir . $path);
$space = @disk_free_space($this->getSourcePath($path));
if ($space === false || is_null($space)) {
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
}
Expand All @@ -232,24 +232,28 @@ public function search($query) {
}

public function getLocalFile($path) {
return $this->datadir . $path;
return $this->getSourcePath($path);
}

public function getLocalFolder($path) {
return $this->datadir . $path;
return $this->getSourcePath($path);
}

/**
* @param string $query
*/
protected function searchInDir($query, $dir = '') {
$files = array();
foreach (scandir($this->datadir . $dir) as $item) {
if ($item == '.' || $item == '..') continue;
$physicalDir = $this->getSourcePath($dir);
foreach (scandir($physicalDir) as $item) {
if ($item == '.' || $item == '..')
continue;
$physicalItem = $physicalDir . '/' . $item;

if (strstr(strtolower($item), strtolower($query)) !== false) {
$files[] = $dir . '/' . $item;
}
if (is_dir($this->datadir . $dir . '/' . $item)) {
if (is_dir($physicalItem)) {
$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
}
}
Expand All @@ -271,6 +275,17 @@ public function hasUpdated($path, $time) {
}
}

/**
* Get the source path (on disk) of a given path
*
* @param string $path
* @return string
*/
protected function getSourcePath($path) {
$fullPath = $this->datadir . $path;
return $fullPath;
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit e733d32

Please sign in to comment.