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' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert target path to source path and pass the function call to the correct storage provider
|
|
|
|
*/
|
2012-06-21 17:07:21 +00:00
|
|
|
class OC_Filestorage_Shared extends OC_Filestorage_Common {
|
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-08-16 00:45:07 +00:00
|
|
|
$this->datadir .= "/";
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-22 23:47:57 +00:00
|
|
|
public function getInternalPath($path) {
|
2011-07-30 23:40:19 +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-30 23:40:19 +00:00
|
|
|
$source = OC_Share::getSource($target);
|
2011-07-05 15:56:02 +00:00
|
|
|
$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) {
|
2012-02-26 02:56:45 +00:00
|
|
|
if ($path == "" || $path == "/" || !$this->is_writable($path)) {
|
2011-07-07 23:22:23 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
2011-08-18 01:58:53 +00:00
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
|
|
|
return $storage->mkdir($this->getInternalPath($source));
|
2011-07-07 23:22:23 +00:00
|
|
|
}
|
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-30 23:40:19 +00:00
|
|
|
OC_Share::unshareFromMySelf($this->datadir.$path);
|
2011-07-31 18:48:23 +00:00
|
|
|
$this->clearFolderSizeCache($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function opendir($path) {
|
2011-06-24 23:20:08 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-07-16 18:24:59 +00:00
|
|
|
$path = $this->datadir.$path;
|
2011-07-30 23:40:19 +00:00
|
|
|
$sharedItems = OC_Share::getItemsInFolder($path);
|
2012-01-01 19:04:16 +00:00
|
|
|
$files = array();
|
|
|
|
foreach ($sharedItems as $item) {
|
|
|
|
// If item is in the root of the shared storage provider and the item exists add it to the fakedirs
|
|
|
|
if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) {
|
|
|
|
$files[] = basename($item['target']);
|
2011-07-16 18:24:59 +00:00
|
|
|
}
|
2011-06-24 23:20:08 +00:00
|
|
|
}
|
2012-02-15 19:19:48 +00:00
|
|
|
OC_FakeDirStream::$dirs['shared']=$files;
|
2012-01-01 19:04:16 +00:00
|
|
|
return opendir('fakedir://shared');
|
2011-06-24 23:20:08 +00:00
|
|
|
} else {
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-24 23:20:08 +00:00
|
|
|
if ($source) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
2011-07-08 22:21:20 +00:00
|
|
|
$dh = $storage->opendir($this->getInternalPath($source));
|
2011-07-30 23:40:19 +00:00
|
|
|
$modifiedItems = OC_Share::getItemsInFolder($source);
|
2011-07-08 22:21:20 +00:00
|
|
|
if ($modifiedItems && $dh) {
|
|
|
|
$sources = array();
|
|
|
|
$targets = array();
|
2011-08-22 16:00:56 +00:00
|
|
|
// Remove any duplicate or trailing '/'
|
|
|
|
$path = preg_replace('{(/)\1+}', "/", $path);
|
|
|
|
$targetFolder = rtrim($this->datadir.$path, "/");
|
2011-07-08 22:21:20 +00:00
|
|
|
foreach ($modifiedItems as $item) {
|
2011-08-22 16:00:56 +00:00
|
|
|
// If the item is in the current directory and the item exists add it to the arrays
|
|
|
|
if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) {
|
2011-08-17 21:43:15 +00:00
|
|
|
// If the item was unshared from self, add it it to the arrays
|
2011-08-17 22:00:37 +00:00
|
|
|
if ($item['permissions'] == OC_Share::UNSHARED) {
|
2011-08-17 21:43:15 +00:00
|
|
|
$sources[] = basename($item['source']);
|
|
|
|
$targets[] = "";
|
|
|
|
} else {
|
|
|
|
$sources[] = basename($item['source']);
|
|
|
|
$targets[] = basename($item['target']);
|
|
|
|
}
|
2011-07-16 18:24:59 +00:00
|
|
|
}
|
2011-07-08 22:21:20 +00:00
|
|
|
}
|
2011-07-16 18:24:59 +00:00
|
|
|
// Don't waste time if there aren't any modified items in the current directory
|
|
|
|
if (empty($sources)) {
|
|
|
|
return $dh;
|
|
|
|
} else {
|
2011-08-22 16:00:56 +00:00
|
|
|
global $FAKEDIRS;
|
2011-08-17 21:43:15 +00:00
|
|
|
$files = array();
|
2011-07-16 18:24:59 +00:00
|
|
|
while (($filename = readdir($dh)) !== false) {
|
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
// If the file isn't in the sources array it isn't modified and can be added as is
|
|
|
|
if (!in_array($filename, $sources)) {
|
|
|
|
$files[] = $filename;
|
|
|
|
// The file has a different name than the source and is added to the fakedirs
|
|
|
|
} else {
|
2011-07-23 18:41:01 +00:00
|
|
|
$target = $targets[array_search($filename, $sources)];
|
|
|
|
// Don't add the file if it was unshared from self by the user
|
|
|
|
if ($target != "") {
|
|
|
|
$files[] = $target;
|
|
|
|
}
|
2011-07-16 18:24:59 +00:00
|
|
|
}
|
2011-07-12 22:22:59 +00:00
|
|
|
}
|
2011-07-08 22:21:20 +00:00
|
|
|
}
|
2011-07-16 18:24:59 +00:00
|
|
|
$FAKEDIRS['shared'] = $files;
|
|
|
|
return opendir('fakedir://shared');
|
2011-07-08 22:21:20 +00:00
|
|
|
}
|
|
|
|
} 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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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 == "/") {
|
2011-06-22 23:47:57 +00:00
|
|
|
$stat["size"] = $this->filesize($path);
|
|
|
|
$stat["mtime"] = $this->filemtime($path);
|
|
|
|
$stat["ctime"] = $this->filectime($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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-08-20 19:43:18 +00:00
|
|
|
|
2011-06-23 01:05:31 +00:00
|
|
|
public function getFolderSize($path) {
|
2011-11-10 15:40:09 +00:00
|
|
|
return 0; //depricated
|
2011-06-23 01:05:31 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 19:43:18 +00:00
|
|
|
private function calculateFolderSize($path) {
|
2011-06-27 15:47:36 +00:00
|
|
|
if ($this->is_file($path)) {
|
|
|
|
$path = dirname($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 != "..") {
|
2011-08-20 19:43:18 +00:00
|
|
|
$subFile = $path."/".$filename;
|
2011-06-27 15:47:36 +00:00
|
|
|
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) {
|
2011-08-20 19:43:18 +00:00
|
|
|
$dbpath = rtrim($this->datadir.$path, "/");
|
2012-05-03 11:06:08 +00:00
|
|
|
// $query = OCP\DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
|
2011-11-09 17:41:57 +00:00
|
|
|
// $result = $query->execute(array($dbpath, $size));
|
2011-06-23 01:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $size;
|
|
|
|
}
|
2011-07-06 16:12:29 +00:00
|
|
|
|
2011-08-20 19:43:18 +00:00
|
|
|
private function clearFolderSizeCache($path) {
|
|
|
|
$path = rtrim($path, "/");
|
|
|
|
$path = preg_replace('{(/)\1+}', "/", $path);
|
2011-07-31 18:48:23 +00:00
|
|
|
if ($this->is_file($path)) {
|
|
|
|
$path = dirname($path);
|
|
|
|
}
|
2011-08-20 19:48:48 +00:00
|
|
|
$dbpath = rtrim($this->datadir.$path, "/");
|
2012-05-03 11:06:08 +00:00
|
|
|
// $query = OCP\DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?");
|
2011-11-09 17:41:57 +00:00
|
|
|
// $result = $query->execute(array($dbpath));
|
2011-07-31 18:48:23 +00:00
|
|
|
if ($path != "/" && $path != "") {
|
|
|
|
$parts = explode("/", $path);
|
|
|
|
$part = array_pop($parts);
|
|
|
|
if (empty($part)) {
|
|
|
|
array_pop($parts);
|
|
|
|
}
|
|
|
|
$parent = implode("/", $parts);
|
|
|
|
$this->clearFolderSizeCache($parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-05 13:00:49 +00:00
|
|
|
public function is_writable($path) {
|
2011-12-16 16:31:31 +00:00
|
|
|
if($path == "" || $path == "/"){
|
|
|
|
return false;
|
|
|
|
}elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) {
|
2011-06-18 17:29:16 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2011-07-30 20:03:32 +00:00
|
|
|
return false;
|
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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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 filectime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$ctime = 0;
|
2011-08-16 00:33:02 +00:00
|
|
|
if ($dh = $this->opendir($path)) {
|
|
|
|
while (($filename = readdir($dh)) !== false) {
|
|
|
|
$tempctime = $this->filectime($filename);
|
|
|
|
if ($tempctime < $ctime) {
|
|
|
|
$ctime = $tempctime;
|
|
|
|
}
|
2011-06-22 22:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 15:40:09 +00:00
|
|
|
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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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-08-16 00:33:02 +00:00
|
|
|
if ($dh = $this->opendir($path)) {
|
|
|
|
while (($filename = readdir($dh)) !== false) {
|
|
|
|
$tempmtime = $this->filemtime($filename);
|
|
|
|
if ($tempmtime > $mtime) {
|
|
|
|
$mtime = $tempmtime;
|
|
|
|
}
|
2011-06-22 22:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 15:40:09 +00:00
|
|
|
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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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 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) {
|
2012-05-30 15:46:49 +00:00
|
|
|
$info = array(
|
|
|
|
'target' => $this->datadir.$path,
|
|
|
|
'source' => $source,
|
|
|
|
);
|
|
|
|
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
|
2011-07-30 23:40:19 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function file_put_contents($path, $data) {
|
2012-02-05 13:00:49 +00:00
|
|
|
if ($this->is_writable($path)) {
|
2011-07-30 20:03:32 +00:00
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
2012-05-30 15:46:49 +00:00
|
|
|
$info = array(
|
|
|
|
'target' => $this->datadir.$path,
|
|
|
|
'source' => $source,
|
|
|
|
);
|
|
|
|
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
|
2011-07-30 23:40:19 +00:00
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
2011-08-20 19:43:18 +00:00
|
|
|
$result = $storage->file_put_contents($this->getInternalPath($source), $data);
|
|
|
|
if ($result) {
|
|
|
|
$this->clearFolderSizeCache($path);
|
|
|
|
}
|
|
|
|
return $result;
|
2011-07-30 20:03:32 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unlink($path) {
|
2011-07-30 20:03:32 +00:00
|
|
|
// The item will be removed from the database, but won't be touched on the owner's filesystem
|
2011-08-17 16:58:09 +00:00
|
|
|
$target = $this->datadir.$path;
|
|
|
|
// Check if the item is inside a shared folder
|
|
|
|
if (OC_Share::getParentFolders($target)) {
|
|
|
|
// If entry for item already exists
|
|
|
|
if (OC_Share::getItem($target)) {
|
2011-08-17 21:43:15 +00:00
|
|
|
OC_Share::unshareFromMySelf($target, false);
|
2011-07-30 20:03:32 +00:00
|
|
|
} else {
|
2011-08-17 21:43:15 +00:00
|
|
|
OC_Share::pullOutOfFolder($target, $target);
|
|
|
|
OC_Share::unshareFromMySelf($target, false);
|
2011-07-30 20:03:32 +00:00
|
|
|
}
|
2011-08-17 16:58:09 +00:00
|
|
|
// Delete the database entry
|
|
|
|
} else {
|
|
|
|
OC_Share::unshareFromMySelf($target);
|
2011-07-15 01:04:09 +00:00
|
|
|
}
|
2011-08-17 16:58:09 +00:00
|
|
|
$this->clearFolderSizeCache($this->getInternalPath($target));
|
2011-07-16 18:58:12 +00:00
|
|
|
return true;
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rename($path1, $path2) {
|
2011-08-17 16:58:09 +00:00
|
|
|
$oldTarget = $this->datadir.$path1;
|
|
|
|
$newTarget = $this->datadir.$path2;
|
|
|
|
// Check if the item is inside a shared folder
|
2011-08-18 01:58:53 +00:00
|
|
|
if ($folders = OC_Share::getParentFolders($oldTarget)) {
|
|
|
|
$root1 = substr($path1, 0, strpos($path1, "/"));
|
|
|
|
$root2 = substr($path1, 0, strpos($path2, "/"));
|
2011-08-18 02:10:25 +00:00
|
|
|
// Prevent items from being moved into different shared folders until versioning (cut and paste) and prevent items going into 'Shared'
|
2011-08-18 01:58:53 +00:00
|
|
|
if ($root1 !== $root2) {
|
|
|
|
return false;
|
2011-08-18 02:10:25 +00:00
|
|
|
// Check if both paths have write permission
|
2012-02-05 13:00:49 +00:00
|
|
|
} else if ($this->is_writable($path1) && $this->is_writable($path2)) {
|
2011-08-17 16:58:09 +00:00
|
|
|
$oldSource = $this->getSource($path1);
|
2011-08-18 01:58:53 +00:00
|
|
|
$newSource = $folders['source'].substr($newTarget, strlen($folders['target']));
|
2011-08-17 16:58:09 +00:00
|
|
|
if ($oldSource) {
|
|
|
|
$storage = OC_Filesystem::getStorage($oldSource);
|
|
|
|
return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
|
|
|
|
}
|
2011-08-18 02:10:25 +00:00
|
|
|
// If the user doesn't have write permission, items can only be renamed and not moved
|
|
|
|
} else if (dirname($path1) !== dirname($path2)) {
|
|
|
|
return false;
|
|
|
|
// The item will be renamed in the database, but won't be touched on the owner's filesystem
|
2011-07-30 20:03:32 +00:00
|
|
|
} else {
|
2011-07-30 23:40:19 +00:00
|
|
|
OC_Share::pullOutOfFolder($oldTarget, $newTarget);
|
2011-07-30 20:03:32 +00:00
|
|
|
// If this is a folder being renamed, call setTarget in case there are any database entries inside the folder
|
|
|
|
if (self::is_dir($path1)) {
|
2011-07-30 23:40:19 +00:00
|
|
|
OC_Share::setTarget($oldTarget, $newTarget);
|
2011-07-30 20:03:32 +00:00
|
|
|
}
|
2011-07-16 18:29:22 +00:00
|
|
|
}
|
2011-08-17 16:58:09 +00:00
|
|
|
} else {
|
|
|
|
OC_Share::setTarget($oldTarget, $newTarget);
|
2011-07-14 23:24:48 +00:00
|
|
|
}
|
2011-08-17 16:58:09 +00:00
|
|
|
$this->clearFolderSizeCache($this->getInternalPath($oldTarget));
|
|
|
|
$this->clearFolderSizeCache($this->getInternalPath($newTarget));
|
|
|
|
return true;
|
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 {
|
2012-02-05 13:00:49 +00:00
|
|
|
if ($this->is_writable($path2)) {
|
2011-07-13 19:27:16 +00:00
|
|
|
$tmpFile = $this->toTmpFile($path1);
|
2011-08-20 19:43:18 +00:00
|
|
|
$result = $this->fromTmpFile($tmpFile, $path2);
|
|
|
|
if ($result) {
|
|
|
|
$this->clearFolderSizeCache($path2);
|
|
|
|
}
|
|
|
|
return $result;
|
2011-07-13 19:27:16 +00:00
|
|
|
} 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) {
|
2012-05-30 15:46:49 +00:00
|
|
|
$info = array(
|
|
|
|
'target' => $this->datadir.$path,
|
|
|
|
'source' => $source,
|
|
|
|
'mode' => $mode,
|
|
|
|
);
|
|
|
|
OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info);
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2012-02-05 13:00:49 +00:00
|
|
|
if ($this->is_writable($path)) {
|
2011-07-13 19:27:16 +00:00
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
2011-08-20 19:43:18 +00:00
|
|
|
$result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source));
|
|
|
|
if ($result) {
|
|
|
|
$this->clearFolderSizeCache($path);
|
|
|
|
}
|
|
|
|
return $result;
|
2011-07-13 19:27:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMimeType($path) {
|
2012-02-08 20:12:20 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-11-10 15:40:09 +00:00
|
|
|
return 'httpd/unix-directory';
|
|
|
|
}
|
2011-06-27 15:47:36 +00:00
|
|
|
$source = $this->getSource($path);
|
2011-06-16 18:40:21 +00:00
|
|
|
if ($source) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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 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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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) {
|
2011-07-30 23:40:19 +00:00
|
|
|
$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-08-20 16:03:03 +00:00
|
|
|
public function search($query) {
|
|
|
|
return $this->searchInDir($query);
|
|
|
|
}
|
|
|
|
|
2012-06-21 17:07:21 +00:00
|
|
|
protected function searchInDir($query, $path = "") {
|
2011-08-20 16:03:03 +00:00
|
|
|
$files = array();
|
|
|
|
if ($dh = $this->opendir($path)) {
|
|
|
|
while (($filename = readdir($dh)) !== false) {
|
|
|
|
if ($filename != "." && $filename != "..") {
|
|
|
|
if (strstr(strtolower($filename), strtolower($query))) {
|
|
|
|
$files[] = $path."/".$filename;
|
|
|
|
}
|
|
|
|
if ($this->is_dir($path."/".$filename)) {
|
|
|
|
$files = array_merge($files, $this->searchInDir($query, $path."/".$filename));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $files;
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
2011-08-20 00:05:57 +00:00
|
|
|
|
|
|
|
public function getLocalFile($path) {
|
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
|
|
|
return $storage->getLocalFile($this->getInternalPath($source));
|
|
|
|
}
|
|
|
|
}
|
2012-02-29 22:42:40 +00:00
|
|
|
public function touch($path, $mtime=null){
|
|
|
|
$source = $this->getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_Filesystem::getStorage($source);
|
|
|
|
return $storage->touch($this->getInternalPath($source),$time);
|
|
|
|
}
|
|
|
|
}
|
2012-05-10 23:56:25 +00:00
|
|
|
|
2012-06-19 15:38:04 +00:00
|
|
|
public static function setup($options) {
|
|
|
|
$user_dir = $options['user_dir'];
|
|
|
|
OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => $user_dir.'/Shared'), $user_dir.'/Shared/');
|
2012-05-10 23:56:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:43:24 +00:00
|
|
|
/**
|
|
|
|
* check if a file or folder has been updated since $time
|
|
|
|
* @param int $time
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasUpdated($path,$time){
|
|
|
|
//TODO
|
|
|
|
return $this->filemtime($path)>$time;
|
|
|
|
}
|
2012-05-10 23:56:25 +00:00
|
|
|
}
|