Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/files
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-08-17 12:57:31 +0400
committerRobin Appelman <icewind@owncloud.com>2013-09-10 20:05:14 +0400
commit507a0450db56214534bbaee1012dac4b44ecc51c (patch)
treebeb65e4b3ec97d7cdbc80f73ce3e097442fba4df /lib/files
parent750e4c4f8f8110a48d7af650da1977ec7a17e507 (diff)
also emit hooks for views that are a subfolder of the user folder
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/view.php89
1 files changed, 57 insertions, 32 deletions
diff --git a/lib/files/view.php b/lib/files/view.php
index cfd7ace1fa6..1e2a95751ff 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -264,18 +264,18 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
and Filesystem::isValidPath($path)
- and !Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
$run = true;
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->shouldEmitHooks($path)) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
- Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
@@ -284,7 +284,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
@@ -297,18 +297,18 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path) && $result !== false) {
+ if ($this->shouldEmitHooks($path) && $result !== false) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
\OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
@@ -350,21 +350,21 @@ class View {
return false;
}
$run = true;
- if ($this->fakeRoot == Filesystem::getRoot() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
+ if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
- } elseif ($this->fakeRoot == Filesystem::getRoot()) {
+ } elseif ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_rename,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -397,22 +397,22 @@ class View {
}
}
}
- if ($this->fakeRoot == Filesystem::getRoot() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
+ if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
)
);
- } elseif ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ } elseif ($this->shouldEmitHooks() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_rename,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2)
)
);
}
@@ -444,13 +444,13 @@ class View {
}
$run = true;
$exists = $this->file_exists($path2);
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_copy,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -459,7 +459,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -469,7 +469,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -502,26 +502,26 @@ class View {
list($count, $result) = \OC_Helper::streamCopy($source, $target);
}
}
- if ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ if ($this->shouldEmitHooks() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_copy,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2)
)
);
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
- array(Filesystem::signal_param_path => $path2)
+ array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
- array(Filesystem::signal_param_path => $path2)
+ array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
return $result;
@@ -612,11 +612,11 @@ class View {
if ($path == null) {
return false;
}
- if (Filesystem::$loaded && $this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->shouldEmitHooks($path)) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_read,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
@@ -650,7 +650,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
and Filesystem::isValidPath($path)
- and !Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
@@ -666,7 +666,7 @@ class View {
$result = $storage->$operation($internalPath);
}
$result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ if ($this->shouldEmitHooks($path) && $result !== false) {
if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
$this->runHooks($hooks, $path, true);
}
@@ -677,10 +677,35 @@ class View {
return null;
}
+ /**
+ * get the path relative to the default root for hook usage
+ *
+ * @param string $path
+ * @return string
+ */
+ private function getHookPath($path) {
+ if (!Filesystem::getView()) {
+ return $path;
+ }
+ return Filesystem::getView()->getRelativePath($this->getAbsolutePath($path));
+ }
+
+ private function shouldEmitHooks($path = '') {
+ if ($path && Cache\Scanner::isPartialFile($path)) {
+ return false;
+ }
+ if (!Filesystem::$loaded) {
+ return false;
+ }
+ $defaultRoot = Filesystem::getRoot();
+ return (strlen($this->fakeRoot) >= strlen($defaultRoot)) && (substr($this->fakeRoot, 0, strlen($defaultRoot)) === $defaultRoot);
+ }
+
private function runHooks($hooks, $path, $post = false) {
+ $path = $this->getHookPath($path);
$prefix = ($post) ? 'post_' : '';
$run = true;
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->shouldEmitHooks($path)) {
foreach ($hooks as $hook) {
if ($hook != 'read') {
\OC_Hook::emit(