Deduplicate code

This commit is contained in:
Joas Schilling 2014-04-28 17:45:03 +02:00
parent c1caaa6241
commit c060f6ec7b
1 changed files with 39 additions and 136 deletions

View File

@ -271,6 +271,39 @@ class View {
return $this->basicOperation('file_get_contents', $path, array('read'));
}
protected function emit_file_hooks_pre($exists, $path, &$run) {
if (!$exists) {
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run,
));
} else {
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run,
));
}
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run,
));
}
protected function emit_file_hooks_post($exists, $path) {
if (!$exists) {
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, array(
Filesystem::signal_param_path => $this->getHookPath($path),
));
} else {
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, array(
Filesystem::signal_param_path => $this->getHookPath($path),
));
}
\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, array(
Filesystem::signal_param_path => $this->getHookPath($path),
));
}
public function file_put_contents($path, $data) {
if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
@ -282,33 +315,7 @@ class View {
$exists = $this->file_exists($path);
$run = true;
if ($this->shouldEmitHooks($path)) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
} else {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_update,
array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run,
)
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
$this->emit_file_hooks_pre($exists, $path, $run);
}
if (!$run) {
return false;
@ -322,24 +329,7 @@ class View {
Updater::writeHook(array(
'path' => $this->getHookPath($path)
));
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
array(Filesystem::signal_param_path => $this->getHookPath($path))
);
} else {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_update,
array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
array(Filesystem::signal_param_path => $this->getHookPath($path))
);
$this->emit_file_hooks_post($exists, $path);
}
\OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $result;
@ -401,30 +391,7 @@ class View {
$run = true;
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
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_create,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
} else {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_update,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run,
)
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_write,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
$this->emit_file_hooks_pre($exists, $path2, $run);
} elseif ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_rename,
@ -481,26 +448,7 @@ class View {
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
Updater::writeHook(array('path' => $this->getHookPath($path2)));
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
} else {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_update,
array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
)
);
$this->emit_file_hooks_post($exists, $path2);
} elseif ($this->shouldEmitHooks() && $result !== false) {
Updater::renameHook(array(
'oldpath' => $this->getHookPath($path1),
@ -553,35 +501,7 @@ class View {
Filesystem::signal_param_run => &$run
)
);
if ($run and !$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
} elseif ($run) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_update,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run,
)
);
}
if ($run) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
}
$this->emit_file_hooks_pre($exists, $path2, $run);
}
if ($run) {
$mp1 = $this->getMountPoint($path1 . $postFix1);
@ -621,24 +541,7 @@ class View {
Filesystem::signal_param_newpath => $this->getHookPath($path2)
)
);
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
} else {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_update,
array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
$this->emit_file_hooks_post($exists, $path2);
}
return $result;
} else {