drop Filesystem::getInternalPath and Filesystem::getStorage in favor of Filesystem::resolvePath

This commit is contained in:
Robin Appelman 2012-10-10 17:46:29 +02:00
parent a2785f57d2
commit 5c6e9518ed
5 changed files with 71 additions and 138 deletions

View File

@ -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;
}

View File

@ -164,37 +164,6 @@ class Filesystem {
return $foundMountPoint;
}
/**
* 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
*

View File

@ -68,19 +68,6 @@ class View {
return $this->fakeRoot;
}
/**
* 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
*
@ -103,19 +90,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 {

View File

@ -44,28 +44,6 @@ class OC_Filesystem {
return \OC\Files\Filesystem::getMountPoint($path);
}
/**
* 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
*

View File

@ -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() {