Browse Source

cleanup the shared storage, always keep the whole share resource

remotes/origin/ldap_group_count
Bjoern Schiessle 12 years ago
parent
commit
3f6e9e0102
  1. 8
      apps/files_sharing/lib/cache.php
  2. 74
      apps/files_sharing/lib/sharedstorage.php

8
apps/files_sharing/lib/cache.php

@ -50,7 +50,7 @@ class Shared_Cache extends Cache {
if ($target === false || $target === $this->storage->getMountPoint()) { if ($target === false || $target === $this->storage->getMountPoint()) {
$target = ''; $target = '';
} }
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getShareType());
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
if (isset($source['path']) && isset($source['fileOwner'])) { if (isset($source['path']) && isset($source['fileOwner'])) {
\OC\Files\Filesystem::initMountPoints($source['fileOwner']); \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
@ -86,7 +86,7 @@ class Shared_Cache extends Cache {
public function get($file) { public function get($file) {
if (is_string($file)) { if (is_string($file)) {
if ($cache = $this->getSourceCache($file)) { if ($cache = $this->getSourceCache($file)) {
$path = 'files/' . $this->storage->getMountPoint();
$path = 'files' . $this->storage->getMountPoint();
$path .= ($file !== '') ? '/' . $file : ''; $path .= ($file !== '') ? '/' . $file : '';
$data = $cache->get($this->files[$file]); $data = $cache->get($this->files[$file]);
$data['displayname_owner'] = \OC_User::getDisplayName($this->storage->getSharedFrom()); $data['displayname_owner'] = \OC_User::getDisplayName($this->storage->getSharedFrom());
@ -141,7 +141,7 @@ class Shared_Cache extends Cache {
$folder = ''; $folder = '';
} }
$dir = 'files/' . $this->storage->getMountPoint();
$dir = 'files' . $this->storage->getMountPoint();
$dir .= ($folder !== '') ? '/' . $folder : ''; $dir .= ($folder !== '') ? '/' . $folder : '';
$cache = $this->getSourceCache($folder); $cache = $this->getSourceCache($folder);
@ -226,7 +226,7 @@ class Shared_Cache extends Cache {
*/ */
public function move($source, $target) { public function move($source, $target) {
if ($cache = $this->getSourceCache($source)) { if ($cache = $this->getSourceCache($source)) {
$file = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getShareType());
$file = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
if ($file && isset($file['path'])) { if ($file && isset($file['path'])) {
$cache->move($this->files[$source], $file['path']); $cache->move($this->files[$source], $file['path']);
} }

74
apps/files_sharing/lib/sharedstorage.php

@ -28,19 +28,11 @@ namespace OC\Files\Storage;
*/ */
class Shared extends \OC\Files\Storage\Common { class Shared extends \OC\Files\Storage\Common {
private $mountPoint; // mount point relative to data/user/files
private $type; // can be "file" or "folder"
private $shareId; // share Id to identify the share in the database
private $fileSource; // file cache ID of the shared item
private $sharedFrom; // the user who shared the file
private $share; // the shared resource
private $files = array(); private $files = array();
public function __construct($arguments) { public function __construct($arguments) {
$this->mountPoint = $arguments['shareTarget'];
$this->type = $arguments['shareType'];
$this->shareId = $arguments['shareId'];
$this->fileSource = $arguments['fileSource'];
$this->sharedFrom = $arguments['sharedFrom'];
$this->share = $arguments['share'];
} }
/** /**
@ -48,7 +40,7 @@ class Shared extends \OC\Files\Storage\Common {
* @return string * @return string
*/ */
public function getId() { public function getId() {
return 'shared::' . $this->mountPoint;
return 'shared::' . $this->getMountPoint();
} }
/** /**
@ -56,7 +48,7 @@ class Shared extends \OC\Files\Storage\Common {
* @return string * @return string
*/ */
public function getSourceId() { public function getSourceId() {
return $this->fileSource;
return $this->share['file_source'];
} }
/** /**
@ -69,14 +61,14 @@ class Shared extends \OC\Files\Storage\Common {
if (!isset($this->files[$target])) { if (!isset($this->files[$target])) {
// Check for partial files // Check for partial files
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
$source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getMountPoint(), $this->getShareType());
$source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getMountPoint(), $this->getItemType());
if ($source) { if ($source) {
$source['path'] .= '.part'; $source['path'] .= '.part';
// All partial files have delete permission // All partial files have delete permission
$source['permissions'] |= \OCP\PERMISSION_DELETE; $source['permissions'] |= \OCP\PERMISSION_DELETE;
} }
} else { } else {
$source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getShareType());
$source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getItemType());
} }
$this->files[$target] = $source; $this->files[$target] = $source;
} }
@ -191,7 +183,7 @@ class Shared extends \OC\Files\Storage\Common {
public function isCreatable($path) { public function isCreatable($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE); return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
} }
@ -202,21 +194,21 @@ class Shared extends \OC\Files\Storage\Common {
public function isUpdatable($path) { public function isUpdatable($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE); return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE);
} }
public function isDeletable($path) { public function isDeletable($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE); return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE);
} }
public function isSharable($path) { public function isSharable($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE); return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE);
} }
@ -241,7 +233,7 @@ class Shared extends \OC\Files\Storage\Common {
$source = $this->getSourcePath($path); $source = $this->getSourcePath($path);
if ($source) { if ($source) {
$info = array( $info = array(
'target' => $this->mountPoint . $path,
'target' => $this->getMountPoint() . $path,
'source' => $source, 'source' => $source,
); );
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
@ -259,7 +251,7 @@ class Shared extends \OC\Files\Storage\Common {
return false; return false;
} }
$info = array( $info = array(
'target' => $this->mountPoint . '/' . $path,
'target' => $this->getMountPoint() . '/' . $path,
'source' => $source, 'source' => $source,
); );
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
@ -332,7 +324,7 @@ class Shared extends \OC\Files\Storage\Common {
WHERE `id` = ?' WHERE `id` = ?'
); );
$result = $query->execute(array($relTargetPath, $this->shareId));
$result = $query->execute(array($relTargetPath, $this->getShareId()));
if ($result) { if ($result) {
// update the mount manager with the new paths // update the mount manager with the new paths
@ -358,7 +350,7 @@ class Shared extends \OC\Files\Storage\Common {
// if we renamed the mount point we need to adjust the file_target in the // if we renamed the mount point we need to adjust the file_target in the
// database // database
if (strlen($sourceMountPoint) >= strlen($path1)) {
if (\OC\Files\Filesystem::normalizePath($sourceMountPoint) === \OC\Files\Filesystem::normalizePath($path1)) {
return $this->renameMountPoint($path1, $path2); return $this->renameMountPoint($path1, $path2);
} }
@ -417,7 +409,7 @@ class Shared extends \OC\Files\Storage\Common {
} }
} }
$info = array( $info = array(
'target' => $this->mountPoint . $path,
'target' => $this->getMountPoint() . $path,
'source' => $source, 'source' => $source,
'mode' => $mode, 'mode' => $mode,
); );
@ -438,7 +430,7 @@ class Shared extends \OC\Files\Storage\Common {
public function free_space($path) { public function free_space($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
$source = $this->getSourcePath($path); $source = $this->getSourcePath($path);
if ($source) { if ($source) {
@ -471,11 +463,7 @@ class Shared extends \OC\Files\Storage\Common {
foreach ($shares as $share) { foreach ($shares as $share) {
\OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
array( array(
'shareTarget' => $share['file_target'],
'shareType' => $share['item_type'],
'shareId' => $share['id'],
'fileSource' => $share['file_source'],
'sharedFrom' => $share['uid_owner'],
'share' => $share,
), ),
$options['user_dir'] . '/' . $share['file_target']); $options['user_dir'] . '/' . $share['file_target']);
} }
@ -487,7 +475,23 @@ class Shared extends \OC\Files\Storage\Common {
* @return string * @return string
*/ */
public function getMountPoint() { public function getMountPoint() {
return ltrim($this->mountPoint, '/');
return $this->share['file_target'];
}
/**
* @brief get share type
* @return integer can be single user share (0) group share (1), unique group share name (2)
*/
private function getShareType() {
return $this->share['share_type'];
}
/**
* @brief get share ID
* @return integer unique share ID
*/
private function getShareId() {
return $this->share['id'];
} }
/** /**
@ -495,15 +499,15 @@ class Shared extends \OC\Files\Storage\Common {
* @return string * @return string
*/ */
public function getSharedFrom() { public function getSharedFrom() {
return $this->sharedFrom;
return $this->share['uid_owner'];
} }
/** /**
* @brief return share type, can be "file" or "folder" * @brief return share type, can be "file" or "folder"
* @return string * @return string
*/ */
public function getShareType() {
return $this->type;
public function getItemType() {
return $this->share['item_type'];
} }
public function hasUpdated($path, $time) { public function hasUpdated($path, $time) {
@ -528,7 +532,7 @@ class Shared extends \OC\Files\Storage\Common {
public function getOwner($path) { public function getOwner($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
$source = $this->getFile($path); $source = $this->getFile($path);
if ($source) { if ($source) {
@ -539,7 +543,7 @@ class Shared extends \OC\Files\Storage\Common {
public function getETag($path) { public function getETag($path) {
if ($path == '') { if ($path == '') {
$path = $this->mountPoint;
$path = $this->getMountPoint();
} }
if ($source = $this->getSourcePath($path)) { if ($source = $this->getSourcePath($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);

Loading…
Cancel
Save