summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-07-10 18:56:22 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-07-10 18:56:22 -0400
commit7c908a0016db30c70271304c4d080383911645e3 (patch)
treecc14759d9476d18310901acb9e48ef7445cb3c8a /apps/files_sharing
parent1ad5e3e39f7e1c6d8279cf8e06781a8e6512b9fe (diff)
downloadnextcloud-server-7c908a0016db30c70271304c4d080383911645e3.tar.gz
nextcloud-server-7c908a0016db30c70271304c4d080383911645e3.zip
Sharing files working using share API
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/app.php4
-rw-r--r--apps/files_sharing/lib/share/file.php94
-rw-r--r--apps/files_sharing/lib/share/folder.php64
-rw-r--r--apps/files_sharing/sharedstorage.php193
4 files changed, 199 insertions, 156 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index a08544909ba..7495a5bbe6c 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -1,7 +1,8 @@
<?php
OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
-OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/share.php";
+OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
+OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/sharedstorage.php";
OCP\App::registerAdmin('files_sharing', 'settings');
@@ -24,3 +25,4 @@ OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
OCP\Util::addStyle( 'files_sharing', 'sharing' );
OCP\Util::addStyle("3rdparty", "chosen/chosen");
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
+OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
new file mode 100644
index 00000000000..86b82b19acd
--- /dev/null
+++ b/apps/files_sharing/lib/share/file.php
@@ -0,0 +1,94 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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/>.
+*/
+
+class OC_Share_Backend_File extends OCP\Share_Backend {
+
+ const FORMAT_SOURCE_PATH = 0;
+ const FORMAT_FILE_APP = 1;
+ const FORMAT_FILE_APP_ROOT = 2;
+ const FORMAT_OPENDIR = 3;
+
+ public function getSource($item, $uid) {
+ if (OC_Filesystem::file_exists($item)) {
+ return array('item' => null, 'file' => $item);
+ }
+ return false;
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return '/Shared'.$item;
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_OPENDIR) {
+ $files = array();
+ foreach ($items as $file) {
+ $files[] = basename($file['file_target']);
+ }
+ return $files;
+ } else {
+ $shares = array();
+ $ids = array();
+ foreach ($items as $item) {
+ $shares[$item['file_source']] = $item;
+ $ids[] = $item['file_source'];
+ }
+ $ids = "'".implode("','", $ids)."'";
+ if ($format == self::FORMAT_SOURCE_PATH) {
+ $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute()->fetchAll();
+ if (isset($result[0]['path'])) {
+ return $result[0]['path'];
+ }
+ return false;
+ } else if ($format == self::FORMAT_FILE_APP) {
+ $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute();
+ $files = array();
+ while ($file = $result->fetchRow()) {
+ // Set target path
+ $file['path'] = $shares[$file['id']]['file_target'];
+ $file['name'] = basename($file['path']);
+ // TODO Set permissions: $file['writable']
+ $files[] = $file;
+ }
+ return $files;
+ } else if ($format == self::FORMAT_FILE_APP_ROOT) {
+ $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute();
+ $mtime = 0;
+ $size = 0;
+ while ($file = $result->fetchRow()) {
+ if ($file['mtime'] > $mtime) {
+ $mtime = $file['mtime'];
+ }
+ $size += $file['size'];
+ }
+ return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false));
+ }
+ }
+ return array();
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
new file mode 100644
index 00000000000..033e2ba9667
--- /dev/null
+++ b/apps/files_sharing/lib/share/folder.php
@@ -0,0 +1,64 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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/>.
+*/
+
+class OC_Share_Backend_Folder extends OC_Share_Backend_File {
+
+ public function inCollection($collections, $item) {
+ // TODO
+ }
+
+ public function getChildrenSources($item) {
+ return OC_FileCache::getFolderContent($item);
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
+ $folder = $items[key($items)];
+ $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id = ?');
+ $result = $query->execute(array($folder['file_source']))->fetchRow();
+ if (isset($result['path'])) {
+ if (isset($parameters['mimetype_filter'])) {
+ $mimetype_filter = $parameters['mimetype_filter'];
+ } else {
+ $mimetype_filter = '';
+ }
+ $pos = strpos($result['path'], $folder['item']);
+ $path = substr($result['path'], $pos).substr($parameters['folder'], strlen($folder['file_target']));
+ $root = substr($result['path'], 0, $pos);
+ return OC_FileCache::getFolderContent($path, $root, $mimetype_filter);
+ }
+ }/* else if ($format == self::FORMAT_OPENDIR_ROOT) {
+ $query = OCP\DB::prepare('SELECT name FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute();
+ $files = array();
+ while ($file = $result->fetchRow()) {
+ // Set target path
+ $files[] = basename($shares[$file['id']]['item_target']);
+ }
+ return $files;
+ }*/
+ return array();
+ }
+
+}
+
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 11a5d39f011..1dfdf133791 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -32,30 +32,25 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$this->sharedFolder = $arguments['sharedFolder'];
}
- public function getSourcePath($target) {
- $target = $this->sharedFolder.$target;
+ private function getSourcePath($target) {
+ $target = $this->sharedFolder.'/'.$target;
+ $target = rtrim($target, '/');
if (isset($this->sourcePaths[$target])) {
return $this->sourcePaths[$target];
} else {
- if (dirname($target) != $this->sharedFolder) {
- $len = strlen($this->sharedFolder);
- $pos = strpos($target, '/', $len);
- // Get shared folder name
- $itemTarget = substr($target, $len, $pos);
- $insideFolder = true;
+ $pos = strpos($target, '/', 8);
+ // Get shared folder name
+ if ($pos !== false) {
+ $itemTarget = substr($target, 0, $pos);
} else {
$itemTarget = $target;
- $insideFolder = false;
}
$sourcePath = OCP\Share::getItemSharedWith('file', $itemTarget, OC_Share_Backend_File::FORMAT_SOURCE_PATH);
if ($sourcePath) {
- if ($insideFolder) {
- $this->sourcePaths[$target] = $sourcePath.substr($target, $pos);
- } else {
- $this->sourcePaths[$target] = $sourcePath;
- }
+ $this->sourcePaths[$target] = $sourcePath.substr($target, strlen($itemTarget));
return $this->sourcePaths[$target];
}
+ OCP\Util::writeLog('files_sharing', 'File source path not found for: '.$target, OCP\Util::ERROR);
return false;
}
}
@@ -70,8 +65,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == "" || $path == "/" || !$this->is_writable($path)) {
return false;
} else {
- $source = $this->getSourcePath($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->mkdir($this->getInternalPath($source));
}
@@ -80,116 +74,54 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public function rmdir($path) {
// The folder will be removed from the database, but won't be deleted from the owner's filesystem
- OC_Share::unshareFromMySelf($this->datadir.$path);
- $this->clearFolderSizeCache($path);
+ // TODO
}
public function opendir($path) {
- if ($path == "" || $path == "/") {
- $path = $this->datadir.$path;
- // TODO
- $sharedItems = OC_Share::getItemsInFolder($path);
- $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']);
- }
- }
- OC_FakeDirStream::$dirs['shared']=$files;
+ if ($path == '' || $path == '/') {
+ $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
+ OC_FakeDirStream::$dirs['shared'] = $files;
return opendir('fakedir://shared');
} else {
- $source = $this->getSourcePath($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
- $dh = $storage->opendir($this->getInternalPath($source));
- $modifiedItems = OC_Share::getItemsInFolder($source);
- if ($modifiedItems && $dh) {
- $sources = array();
- $targets = array();
- // Remove any duplicate or trailing '/'
- $path = preg_replace('{(/)\1+}', "/", $path);
- $targetFolder = rtrim($this->datadir.$path, "/");
- foreach ($modifiedItems as $item) {
- // 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']))) {
- // If the item was unshared from self, add it it to the arrays
- if ($item['permissions'] == OC_Share::UNSHARED) {
- $sources[] = basename($item['source']);
- $targets[] = "";
- } else {
- $sources[] = basename($item['source']);
- $targets[] = basename($item['target']);
- }
- }
- }
- // Don't waste time if there aren't any modified items in the current directory
- if (empty($sources)) {
- return $dh;
- } else {
- global $FAKEDIRS;
- $files = array();
- 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 {
- $target = $targets[array_search($filename, $sources)];
- // Don't add the file if it was unshared from self by the user
- if ($target != "") {
- $files[] = $target;
- }
- }
- }
- }
- $FAKEDIRS['shared'] = $files;
- return opendir('fakedir://shared');
- }
- } else {
- return $dh;
- }
+ return $storage->opendir($this->getInternalPath($source));
}
}
}
-
+
public function is_dir($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
return true;
} else {
- $source = $this->getSourcePath($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_dir($this->getInternalPath($source));
}
}
}
-
+
public function is_file($path) {
- $source = $this->getSourcePath($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_file($this->getInternalPath($source));
}
}
-
- // TODO fill in other components of array
+
public function stat($path) {
- if ($path == "" || $path == "/") {
- $stat["size"] = $this->filesize($path);
- $stat["mtime"] = $this->filemtime($path);
- $stat["ctime"] = $this->filectime($path);
+ if ($path == '' || $path == '/') {
+ $stat['size'] = $this->filesize($path);
+ $stat['mtime'] = $this->filemtime($path);
+ $stat['ctime'] = $this->filectime($path);
return $stat;
} else {
- $source = $this->getSourcePath($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->stat($this->getInternalPath($source));
}
}
}
-
+
public function filetype($path) {
if ($path == "" || $path == "/") {
return "dir";
@@ -202,7 +134,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
}
-
+
public function filesize($path) {
if ($path == "" || $path == "/" || $this->is_dir($path)) {
return $this->getFolderSize($path);
@@ -215,55 +147,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
}
- public function getFolderSize($path) {
- return 0; //depricated
- }
-
- private function calculateFolderSize($path) {
- if ($this->is_file($path)) {
- $path = dirname($path);
- }
- $size = 0;
- if ($dh = $this->opendir($path)) {
- 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);
- }
- }
- }
- if ($size > 0) {
- $dbpath = rtrim($this->datadir.$path, "/");
-// $query = OCP\DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
-// $result = $query->execute(array($dbpath, $size));
- }
- }
- return $size;
- }
-
- private function clearFolderSizeCache($path) {
- $path = rtrim($path, "/");
- $path = preg_replace('{(/)\1+}', "/", $path);
- if ($this->is_file($path)) {
- $path = dirname($path);
- }
- $dbpath = rtrim($this->datadir.$path, "/");
-// $query = OCP\DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?");
-// $result = $query->execute(array($dbpath));
- if ($path != "/" && $path != "") {
- $parts = explode("/", $path);
- $part = array_pop($parts);
- if (empty($part)) {
- array_pop($parts);
- }
- $parent = implode("/", $parts);
- $this->clearFolderSizeCache($parent);
- }
- }
-
public function is_readable($path) {
return true;
}
@@ -271,7 +154,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public function is_writable($path) {
if($path == "" || $path == "/"){
return false;
- }elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) {
+ }elseif (OC_Share::getPermissions($this->sharedFolder.$path) & OC_Share::WRITE) {
return true;
} else {
return false;
@@ -336,7 +219,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
- 'target' => $this->datadir.$path,
+ 'target' => $this->sharedFolder.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
@@ -350,7 +233,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
- 'target' => $this->datadir.$path,
+ 'target' => $this->sharedFolder.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
@@ -366,7 +249,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public function unlink($path) {
// The item will be removed from the database, but won't be touched on the owner's filesystem
- $target = $this->datadir.$path;
+ $target = $this->sharedFolder.$path;
// Check if the item is inside a shared folder
if (OC_Share::getParentFolders($target)) {
// If entry for item already exists
@@ -385,8 +268,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function rename($path1, $path2) {
- $oldTarget = $this->datadir.$path1;
- $newTarget = $this->datadir.$path2;
+ $oldTarget = $this->sharedFolder.$path1;
+ $newTarget = $this->sharedFolder.$path2;
// Check if the item is inside a shared folder
if ($folders = OC_Share::getParentFolders($oldTarget)) {
$root1 = substr($path1, 0, strpos($path1, "/"));
@@ -442,7 +325,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
- 'target' => $this->datadir.$path,
+ 'target' => $this->sharedFolder.$path,
'source' => $source,
'mode' => $mode,
);
@@ -541,7 +424,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public static function setup($options) {
$user_dir = $options['user_dir'];
- OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => $user_dir.'/Shared'), $user_dir.'/Shared/');
+ OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
}
/**
@@ -551,6 +434,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
*/
public function hasUpdated($path,$time){
//TODO
- return $this->filemtime($path)>$time;
+ return false;
}
}