aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-10-10 17:46:29 +0200
committerRobin Appelman <icewind@owncloud.com>2012-10-10 17:46:29 +0200
commit5c6e9518edde10e0c23d0d734d2cc6d161fc15c0 (patch)
treeac40020d415b2eaeeac88d09053f4d21a3fe876d
parenta2785f57d2335d06f3fa9900298343c1d7f9253a (diff)
downloadnextcloud-server-5c6e9518edde10e0c23d0d734d2cc6d161fc15c0.tar.gz
nextcloud-server-5c6e9518edde10e0c23d0d734d2cc6d161fc15c0.zip
drop Filesystem::getInternalPath and Filesystem::getStorage in favor of Filesystem::resolvePath
-rw-r--r--apps/files_sharing/lib/sharedstorage.php86
-rw-r--r--lib/files/filesystem.php31
-rw-r--r--lib/files/view.php61
-rw-r--r--lib/filesystem.php22
-rw-r--r--tests/lib/filesystem.php9
5 files changed, 71 insertions, 138 deletions
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index e17c4b6e043..e12027a4f2b 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -114,16 +114,16 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->mkdir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->mkdir($internalPath);
}
return false;
}
public function rmdir($path) {
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->rmdir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->rmdir($internalPath);
}
return false;
}
@@ -134,8 +134,8 @@ class Shared extends \OC\Files\Storage\Common {
\OC_FakeDirStream::$dirs['shared'] = $files;
return opendir('fakedir://shared');
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->opendir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->opendir($internalPath);
}
return false;
}
@@ -144,16 +144,16 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->is_dir($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_dir($internalPath);
}
return false;
}
public function is_file($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->is_file($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_file($internalPath);
}
return false;
}
@@ -165,8 +165,8 @@ class Shared extends \OC\Files\Storage\Common {
$stat['ctime'] = $this->filectime($path);
return $stat;
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->stat($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->stat($internalPath);
}
return false;
}
@@ -175,8 +175,8 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->filetype($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filetype($internalPath);
}
return false;
}
@@ -185,8 +185,8 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->filesize($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filesize($internalPath);
}
return false;
}
@@ -227,8 +227,8 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->file_exists($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_exists($internalPath);
}
return false;
}
@@ -248,8 +248,8 @@ class Shared extends \OC\Files\Storage\Common {
} else {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->filectime($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filectime($internalPath);
}
}
}
@@ -269,8 +269,8 @@ class Shared extends \OC\Files\Storage\Common {
} else {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->filemtime($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->filemtime($internalPath);
}
}
}
@@ -283,8 +283,8 @@ class Shared extends \OC\Files\Storage\Common {
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->file_get_contents($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_get_contents($internalPath);
}
}
@@ -299,8 +299,8 @@ class Shared extends \OC\Files\Storage\Common {
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
- $storage = \OC\Files\Filesystem::getStorage($source);
- $result = $storage->file_put_contents($this->getInternalPath($source), $data);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ $result = $storage->file_put_contents($internalPath, $data);
return $result;
}
return false;
@@ -310,8 +310,8 @@ class Shared extends \OC\Files\Storage\Common {
// Delete the file if DELETE permission is granted
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->unlink($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->unlink($internalPath);
} else if (dirname($path) == '/' || dirname($path) == '.') {
// Unshare the file from the user if in the root of the Shared folder
if ($this->is_dir($path)) {
@@ -334,8 +334,9 @@ class Shared extends \OC\Files\Storage\Common {
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
- $storage = \OC\Files\Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
} else {
// Move the file if DELETE and CREATE permissions are granted
@@ -349,8 +350,9 @@ class Shared extends \OC\Files\Storage\Common {
return $this->unlink($path1);
}
} else {
- $storage = \OC\Files\Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath)=\OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath)=\OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
}
}
@@ -395,8 +397,8 @@ class Shared extends \OC\Files\Storage\Common {
'mode' => $mode,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->fopen($this->getInternalPath($source), $mode);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->fopen($internalPath, $mode);
}
return false;
}
@@ -406,8 +408,8 @@ class Shared extends \OC\Files\Storage\Common {
return 'httpd/unix-directory';
}
if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->getMimeType($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->getMimeType($internalPath);
}
return false;
}
@@ -415,22 +417,22 @@ class Shared extends \OC\Files\Storage\Common {
public function free_space($path) {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->free_space($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->free_space($internalPath);
}
}
public function getLocalFile($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->getLocalFile($this->getInternalPath($source));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->getLocalFile($internalPath);
}
return false;
}
public function touch($path, $mtime = null) {
if ($source = $this->getSourcePath($path)) {
- $storage = \OC\Files\Filesystem::getStorage($source);
- return $storage->touch($this->getInternalPath($source), $mtime);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($source);
+ return $storage->touch($internalPath, $mtime);
}
return false;
}
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index f23f3a79e98..841f30c7679 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -165,37 +165,6 @@ class Filesystem {
}
/**
- * get the part of the path relative to the mountpoint of the storage it's stored in
- *
- * @param string $path
- * @return bool
- */
- static public function getInternalPath($path) {
- $mountPoint = self::getMountPoint($path);
- $internalPath = substr($path, strlen($mountPoint));
- return $internalPath;
- }
-
- /**
- * get the storage object for a path
- *
- * @param string $path
- * @return \OC\Files\Storage\Storage
- */
- static public function getStorage($path) {
- $mountpoint = self::getMountPoint($path);
- if ($mountpoint) {
- if (!isset(self::$storages[$mountpoint])) {
- $mount = self::$mounts[$mountpoint];
- self::$storages[$mountpoint] = self::createStorage($mount['class'], $mount['arguments']);
- }
- return self::$storages[$mountpoint];
- }else{
- return null;
- }
- }
-
- /**
* resolve a path to a storage and internal path
*
* @param string $path
diff --git a/lib/files/view.php b/lib/files/view.php
index 230455479cf..bffeb434f28 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -69,19 +69,6 @@ class View {
}
/**
- * get the part of the path relative to the mountpoint of the storage it's stored in
- *
- * @param string $path
- * @return bool
- */
- public function getInternalPath($path) {
- if (!isset($this->internal_path_cache[$path])) {
- $this->internal_path_cache[$path] = Filesystem::getInternalPath($this->getAbsolutePath($path));
- }
- return $this->internal_path_cache[$path];
- }
-
- /**
* get path relative to the root of the view
*
* @param string $path
@@ -104,19 +91,6 @@ class View {
}
/**
- * get the storage object for a path
- *
- * @param string $path
- * @return \OC\Files\Storage\Storage
- */
- public function getStorage($path) {
- if (!isset($this->storage_cache[$path])) {
- $this->storage_cache[$path] = Filesystem::getStorage($this->getAbsolutePath($path));
- }
- return $this->storage_cache[$path];
- }
-
- /**
* get the mountpoint of the storage object for a path
( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account
*
@@ -136,8 +110,9 @@ class View {
*/
public function getLocalFile($path) {
$parent = substr($path, 0, strrpos($path, '/'));
- if (Filesystem::isValidPath($parent) and $storage = $this->getStorage($path)) {
- return $storage->getLocalFile($this->getInternalPath($path));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($path);
+ if (Filesystem::isValidPath($parent) and $storage) {
+ return $storage->getLocalFile($internalPath);
} else {
return null;
}
@@ -149,8 +124,9 @@ class View {
*/
public function getLocalFolder($path) {
$parent = substr($path, 0, strrpos($path, '/'));
- if (Filesystem::isValidPath($parent) and $storage = $this->getStorage($path)) {
- return $storage->getLocalFolder($this->getInternalPath($path));
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($path);
+ if (Filesystem::isValidPath($parent) and $storage) {
+ return $storage->getLocalFolder($internalPath);
} else {
return null;
}
@@ -373,8 +349,10 @@ class View {
$mp1 = $this->getMountPoint($path1 . $postFix1);
$mp2 = $this->getMountPoint($path2 . $postFix2);
if ($mp1 == $mp2) {
- if ($storage = $this->getStorage($path1)) {
- $result = $storage->rename($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2));
+ list($storage, $internalPath1)=\OC\Files\Filesystem::resolvePath($path1 . $postFix1);
+ list( , $internalPath2)=\OC\Files\Filesystem::resolvePath($path2 . $postFix2);
+ if ($storage) {
+ $result = $storage->rename($internalPath1, $internalPath2);
} else {
$result = false;
}
@@ -382,8 +360,8 @@ class View {
$source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w');
$count = \OC_Helper::streamCopy($source, $target);
- $storage1 = $this->getStorage($path1);
- $storage1->unlink($this->getInternalPath($path1 . $postFix1));
+ list($storage1, $internalPath1)=\OC\Files\Filesystem::resolvePath($path1 . $postFix1);
+ $storage1->unlink($internalPath1);
$result = $count > 0;
}
if ($this->fakeRoot == Filesystem::getRoot()) {
@@ -454,8 +432,10 @@ class View {
$mp1 = $this->getMountPoint($path1 . $postFix1);
$mp2 = $this->getMountPoint($path2 . $postFix2);
if ($mp1 == $mp2) {
- if ($storage = $this->getStorage($path1 . $postFix1)) {
- $result = $storage->copy($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2));
+ list($storage, $internalPath1)=\OC\Files\Filesystem::resolvePath($path1 . $postFix1);
+ list( , $internalPath2)=\OC\Files\Filesystem::resolvePath($path2 . $postFix2);
+ if ($storage) {
+ $result = $storage->copy($internalPath1, $internalPath2);
} else {
$result = false;
}
@@ -588,8 +568,9 @@ class View {
array(Filesystem::signal_param_path => $path)
);
}
- if ($storage = $this->getStorage($path . $postFix)) {
- $result = $storage->hash($type, $this->getInternalPath($path . $postFix), $raw);
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($path . $postFix);
+ if ($storage) {
+ $result = $storage->hash($type, $internalPath, $raw);
$result = \OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
return $result;
}
@@ -621,9 +602,9 @@ class View {
if ($path == null) {
return false;
}
- $internalPath = $this->getInternalPath($path . $postFix);
$run = $this->runHooks($hooks, $path);
- if ($run and $storage = $this->getStorage($path . $postFix)) {
+ list($storage, $internalPath)=\OC\Files\Filesystem::resolvePath($path . $postFix);
+ if ($run and $storage) {
if (!is_null($extraParam)) {
$result = $storage->$operation($internalPath, $extraParam);
} else {
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 4189fe36c2b..587eb50d9e0 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -45,28 +45,6 @@ class OC_Filesystem {
}
/**
- * get the part of the path relative to the mountpoint of the storage it's stored in
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return bool
- */
- static public function getInternalPath($path) {
- return \OC\Files\Filesystem::getInternalPath($path);
- }
-
- /**
- * get the storage object for a path
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return \OC\Files\Storage\Storage
- */
- static public function getStorage($path) {
- return \OC\Files\Filesystem::getStorage($path);
- }
-
- /**
* resolve a path to a storage and internal path
*
* @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
index af3620f5707..6e7b4fb781f 100644
--- a/tests/lib/filesystem.php
+++ b/tests/lib/filesystem.php
@@ -51,15 +51,18 @@ class Test_Filesystem extends UnitTestCase {
Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
$this->assertEqual('/',Filesystem::getMountPoint('/'));
$this->assertEqual('/',Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('',Filesystem::getInternalPath('/'));
- $this->assertEqual('some/folder',Filesystem::getInternalPath('/some/folder'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
+ $this->assertEqual('',$internalPath);
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEqual('some/folder',$internalPath);
Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
$this->assertEqual('/',Filesystem::getMountPoint('/'));
$this->assertEqual('/some/',Filesystem::getMountPoint('/some/folder'));
$this->assertEqual('/some/',Filesystem::getMountPoint('/some/'));
$this->assertEqual('/',Filesystem::getMountPoint('/some'));
- $this->assertEqual('folder',Filesystem::getInternalPath('/some/folder'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEqual('folder',$internalPath);
}
public function testNormalize() {