2011-06-11 20:14:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Michael Gapczynski
|
|
|
|
* @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
require_once( 'lib_share.php' );
|
|
|
|
|
|
|
|
OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datadir'=>'string'));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert target path to source path and pass the function call to the correct storage provider
|
|
|
|
*/
|
2011-07-06 19:17:03 +00:00
|
|
|
class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
|
2011-06-16 18:40:21 +00:00
|
|
|
|
2011-07-12 17:10:29 +00:00
|
|
|
private $datadir;
|
2011-06-27 15:47:36 +00:00
|
|
|
private $sourcePaths = array();
|
|
|
|
|
2011-07-12 17:10:29 +00:00
|
|
|
public function __construct($arguments) {
|
|
|
|
$this->datadir = $arguments['datadir'];
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-22 23:47:57 +00:00
|
|
|
public function getInternalPath($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
$mountPoint = OC_FILESYSTEM::getMountPoint($path);
|
2011-06-27 15:47:36 +00:00
|
|
|
$internalPath = substr($path, strlen($mountPoint));
|
2011-06-18 17:29:16 +00:00
|
|
|
return $internalPath;
|
|
|
|
}
|
|
|
|
|
2011-06-27 15:47:36 +00:00
|
|
|
public function getSource($target) {
|
2011-07-12 17:10:29 +00:00
|
|
|
$target = $this->datadir.$target;
|
2011-07-05 15:56:02 +00:00
|
|
|
if (array_key_exists($target, $this->sourcePaths)) {
|
2011-06-27 15:47:36 +00:00
|
|
|
return $this->sourcePaths[$target];
|
|
|
|
} else {
|
2011-07-05 15:56:02 +00:00
|
|
|
$source = OC_SHARE::getSource($target);
|
|
|
|
$this->sourcePaths[$target] = $source;
|
|
|
|
return $source;
|
2011-06-27 15:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
public function mkdir($path) {
|
2011-07-07 23:22:23 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
2011-07-12 17:10:29 +00:00
|
|
|
if (OC_SHARE::isWriteable($this->datadir.$path)) {
|
2011-07-07 23:22:23 +00:00
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
|
|
|
return $storage->mkdir($this->getInternalPath($source));
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rmdir($path) {
|
2011-07-07 23:22:23 +00:00
|
|
|
// The folder will be removed from the database, but won't be deleted from the owner's filesystem
|
2011-07-14 23:24:48 +00:00
|
|
|
OC_SHARE::unshareFromMySelf($this->datadir.$path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-12 17:10:29 +00:00
|
|
|
// TODO Make sure new target is still in the current directory
|
2011-06-16 18:40:21 +00:00
|
|
|
public function opendir($path) {
|
2011-06-24 23:20:08 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
global $FAKEDIRS;
|
2011-07-14 23:24:48 +00:00
|
|
|
$sharedItems = OC_SHARE::getItemsInFolder($this->datadir.$path);
|
2011-06-24 23:20:08 +00:00
|
|
|
foreach ($sharedItems as $item) {
|
2011-07-12 17:10:29 +00:00
|
|
|
// TODO Implement a better fix
|
|
|
|
$files[] = substr($item['target'], strpos($item['target'], "Share") + 5);
|
2011-06-24 23:20:08 +00:00
|
|
|
}
|
|
|
|
$FAKEDIRS['shared'] = $files;
|
|
|
|
return opendir('fakedir://shared');
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-24 23:20:08 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-07-08 22:21:20 +00:00
|
|
|
$dh = $storage->opendir($this->getInternalPath($source));
|
2011-07-14 23:24:48 +00:00
|
|
|
$modifiedItems = OC_SHARE::getItemsInFolder($this->datadir.$path);
|
2011-07-08 22:21:20 +00:00
|
|
|
if ($modifiedItems && $dh) {
|
|
|
|
global $FAKEDIRS;
|
|
|
|
$sources = array();
|
|
|
|
$targets = array();
|
|
|
|
foreach ($modifiedItems as $item) {
|
|
|
|
$sources[] = basename($item['source']);
|
|
|
|
$targets[] = basename($item['target']);
|
|
|
|
}
|
|
|
|
while (($filename = readdir($dh)) !== false) {
|
2011-07-12 22:22:59 +00:00
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
if (!in_array($filename, $sources)) {
|
|
|
|
$files[] = $filename;
|
|
|
|
} else {
|
|
|
|
$files[] = $targets[array_search($filename, $sources)];
|
|
|
|
}
|
2011-07-08 22:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$FAKEDIRS['shared'] = $files;
|
|
|
|
return opendir('fakedir://shared');
|
|
|
|
} else {
|
|
|
|
return $dh;
|
|
|
|
}
|
2011-06-24 23:20:08 +00:00
|
|
|
}
|
2011-06-22 15:40:09 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function is_dir($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_dir($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function is_file($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_file($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-22 15:40:09 +00:00
|
|
|
|
|
|
|
// TODO fill in other components of array
|
2011-06-16 18:40:21 +00:00
|
|
|
public function stat($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
$stat["dev"] = "";
|
|
|
|
$stat["ino"] = "";
|
|
|
|
$stat["mode"] = "";
|
|
|
|
$stat["nlink"] = "";
|
|
|
|
$stat["uid"] = "";
|
|
|
|
$stat["gid"] = "";
|
|
|
|
$stat["rdev"] = "";
|
2011-06-22 23:47:57 +00:00
|
|
|
$stat["size"] = $this->filesize($path);
|
|
|
|
$stat["atime"] = $this->fileatime($path);
|
|
|
|
$stat["mtime"] = $this->filemtime($path);
|
|
|
|
$stat["ctime"] = $this->filectime($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
$stat["blksize"] = "";
|
|
|
|
$stat["blocks"] = "";
|
|
|
|
return $stat;
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->stat($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filetype($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 15:40:09 +00:00
|
|
|
return "dir";
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filetype($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
2011-06-18 17:29:16 +00:00
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function filesize($path) {
|
2011-06-23 01:05:31 +00:00
|
|
|
if ($path == "" || $path == "/" || $this->is_dir($path)) {
|
|
|
|
return $this->getFolderSize($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filesize($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:05:31 +00:00
|
|
|
public function getFolderSize($path) {
|
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
$dbpath = $_SESSION['user_id']."/files/Share/";
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-24 23:52:35 +00:00
|
|
|
$dbpath = $this->getInternalPath($source);
|
2011-06-23 01:05:31 +00:00
|
|
|
}
|
|
|
|
$query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
|
|
|
|
$size = $query->execute(array($dbpath))->fetchAll();
|
|
|
|
if (count($size) > 0) {
|
|
|
|
return $size[0]['size'];
|
|
|
|
} else {
|
|
|
|
return $this->calculateFolderSize($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function calculateFolderSize($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
if ($this->is_file($path)) {
|
|
|
|
$path = dirname($path);
|
|
|
|
}
|
|
|
|
$path = str_replace("//", "/", $path);
|
|
|
|
if ($this->is_dir($path) && substr($path, -1) != "/") {
|
|
|
|
$path .= "/";
|
|
|
|
}
|
2011-06-23 01:05:31 +00:00
|
|
|
$size = 0;
|
|
|
|
if ($dh = $this->opendir($path)) {
|
2011-06-27 15:47:36 +00:00
|
|
|
while (($filename = readdir($dh)) !== false) {
|
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
$subFile = $path.$filename;
|
|
|
|
if ($this->is_file($subFile)) {
|
|
|
|
$size += $this->filesize($subFile);
|
|
|
|
} else {
|
|
|
|
$size += $this->getFolderSize($subFile);
|
|
|
|
}
|
2011-06-23 01:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($size > 0) {
|
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
$dbpath = $_SESSION['user_id']."/files/Share/";
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
|
|
|
$dbpath = $this->getInternalPath($source);
|
2011-06-23 01:05:31 +00:00
|
|
|
}
|
|
|
|
$query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
|
|
|
|
$result = $query->execute(array($dbpath, $size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $size;
|
|
|
|
}
|
2011-07-06 16:12:29 +00:00
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
public function is_readable($path) {
|
2011-07-06 16:12:29 +00:00
|
|
|
return true;
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function is_writeable($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-07-12 17:10:29 +00:00
|
|
|
return OC_SHARE::isWriteable($this->datadir.$path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function file_exists($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_exists($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function readfile($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->readfile($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filectime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$ctime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempctime = $this->filectime($filename);
|
2011-06-22 23:17:31 +00:00
|
|
|
if ($tempctime < $ctime) {
|
2011-06-22 22:16:41 +00:00
|
|
|
$ctime = $tempctime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ctime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filectime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filemtime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$mtime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempmtime = $this->filemtime($filename);
|
2011-06-22 22:16:41 +00:00
|
|
|
if ($tempmtime > $mtime) {
|
|
|
|
$mtime = $tempmtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $mtime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filemtime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fileatime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$atime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempatime = $this->fileatime($filename);
|
2011-06-22 22:16:41 +00:00
|
|
|
if ($tempatime > $atime) {
|
|
|
|
$atime = $tempatime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $atime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fileatime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function file_get_contents($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_get_contents($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function file_put_contents($path, $data) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_put_contents($this->getInternalPath($source), $data);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unlink($path) {
|
2011-07-15 01:04:09 +00:00
|
|
|
// The file will be removed from the database, but won't be touched on the owner's filesystem
|
|
|
|
$target = $this->datadir.$path;
|
2011-07-16 17:06:59 +00:00
|
|
|
// If file is inside a shared folder
|
|
|
|
if (OC_SHARE::getParentFolders($target)) {
|
|
|
|
// If entry for file already exists
|
|
|
|
if (OC_SHARE::getItem($target)) {
|
|
|
|
OC_SHARE::setTarget($target, "/");
|
|
|
|
} else {
|
|
|
|
OC_SHARE::pullOutOfFolder($target, "/");
|
|
|
|
}
|
2011-07-15 01:04:09 +00:00
|
|
|
} else {
|
2011-07-16 17:06:59 +00:00
|
|
|
OC_SHARE::unshareFromMySelf($target);
|
2011-07-15 01:04:09 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rename($path1, $path2) {
|
2011-07-15 01:04:09 +00:00
|
|
|
// The file will be renamed in the database, but won't be touched on the owner's filesystem
|
|
|
|
$oldTarget = $this->datadir.$path1;
|
|
|
|
$newTarget = $this->datadir.$path2;
|
2011-07-16 17:06:59 +00:00
|
|
|
if (OC_SHARE::getItem($oldTarget)) {
|
2011-07-15 01:04:09 +00:00
|
|
|
OC_SHARE::setTarget($oldTarget, $newTarget);
|
2011-07-14 23:24:48 +00:00
|
|
|
} else {
|
2011-07-15 01:04:09 +00:00
|
|
|
OC_SHARE::pullOutOfFolder($oldTarget, $newTarget);
|
2011-07-14 23:24:48 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function copy($path1, $path2) {
|
2011-07-13 19:27:16 +00:00
|
|
|
if ($path2 == "" || $path2 == "/") {
|
|
|
|
// TODO Construct new shared item or should this not be allowed?
|
|
|
|
} else {
|
|
|
|
if ($this->is_writeable($path)) {
|
|
|
|
$tmpFile = $this->toTmpFile($path1);
|
|
|
|
return $this->fromTmpFile($tmpFile, $path2);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fopen($path, $mode) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fopen($this->getInternalPath($source), $mode);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toTmpFile($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->toTmpFile($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 19:27:16 +00:00
|
|
|
public function fromTmpFile($tmpFile, $path) {
|
|
|
|
if ($this->is_writeable($path)) {
|
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
|
|
|
return $storage->fromTmpFile($tmpFile, $this->getInternalPath($source));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fromUploadedFile($tmpPath, $path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($tmpPath);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fromUploadedFile($this->getInternalPath($source), $path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMimeType($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->getMimeType($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delTree($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->delTree($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function find($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->find($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTree($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->getTree($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hash($type, $path, $raw) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->hash($type, $this->getInternalPath($source), $raw);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function free_space($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->free_space($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-11 20:14:24 +00:00
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
// TODO query all shared files?
|
|
|
|
public function search($query) {
|
|
|
|
|
|
|
|
}
|
2011-06-11 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|