Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
4481a841
Commit
4481a841
authored
11 years ago
by
Thomas Müller
Browse files
Options
Downloads
Plain Diff
Merge pull request #8132 from owncloud/issue/8131
Issue/8131 Fix emitting of filesystem related hooks
parents
654a6e6c
ced2a4fc
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/files/filesystem.php
+16
-0
16 additions, 0 deletions
lib/private/files/filesystem.php
lib/private/files/view.php
+41
-77
41 additions, 77 deletions
lib/private/files/view.php
tests/lib/files/view.php
+33
-13
33 additions, 13 deletions
tests/lib/files/view.php
with
90 additions
and
90 deletions
lib/private/files/filesystem.php
+
16
−
0
View file @
4481a841
...
@@ -118,6 +118,22 @@ class Filesystem {
...
@@ -118,6 +118,22 @@ class Filesystem {
*/
*/
const
signal_post_write
=
'post_write'
;
const
signal_post_write
=
'post_write'
;
/**
* signal emitted before file/dir update
*
* @param string $path
* @param bool $run changing this flag to false in hook handler will cancel event
*/
const
signal_update
=
'update'
;
/**
* signal emitted after file/dir update
*
* @param string $path
* @param bool $run changing this flag to false in hook handler will cancel event
*/
const
signal_post_update
=
'post_update'
;
/**
/**
* signal emits when reading file/dir
* signal emits when reading file/dir
*
*
...
...
This diff is collapsed.
Click to expand it.
lib/private/files/view.php
+
41
−
77
View file @
4481a841
...
@@ -271,6 +271,39 @@ class View {
...
@@ -271,6 +271,39 @@ class View {
return
$this
->
basicOperation
(
'file_get_contents'
,
$path
,
array
(
'read'
));
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
)
{
public
function
file_put_contents
(
$path
,
$data
)
{
if
(
is_resource
(
$data
))
{
//not having to deal with streams in file_put_contents makes life easier
if
(
is_resource
(
$data
))
{
//not having to deal with streams in file_put_contents makes life easier
$absolutePath
=
Filesystem
::
normalizePath
(
$this
->
getAbsolutePath
(
$path
));
$absolutePath
=
Filesystem
::
normalizePath
(
$this
->
getAbsolutePath
(
$path
));
...
@@ -282,24 +315,7 @@ class View {
...
@@ -282,24 +315,7 @@ class View {
$exists
=
$this
->
file_exists
(
$path
);
$exists
=
$this
->
file_exists
(
$path
);
$run
=
true
;
$run
=
true
;
if
(
$this
->
shouldEmitHooks
(
$path
))
{
if
(
$this
->
shouldEmitHooks
(
$path
))
{
if
(
!
$exists
)
{
$this
->
emit_file_hooks_pre
(
$exists
,
$path
,
$run
);
\OC_Hook
::
emit
(
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_create
,
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
)
);
}
}
if
(
!
$run
)
{
if
(
!
$run
)
{
return
false
;
return
false
;
...
@@ -313,18 +329,7 @@ class View {
...
@@ -313,18 +329,7 @@ class View {
Updater
::
writeHook
(
array
(
Updater
::
writeHook
(
array
(
'path'
=>
$this
->
getHookPath
(
$path
)
'path'
=>
$this
->
getHookPath
(
$path
)
));
));
if
(
!
$exists
)
{
$this
->
emit_file_hooks_post
(
$exists
,
$path
);
\OC_Hook
::
emit
(
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_post_create
,
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
))
);
}
}
\OC_FileProxy
::
runPostProxies
(
'file_put_contents'
,
$absolutePath
,
$count
);
\OC_FileProxy
::
runPostProxies
(
'file_put_contents'
,
$absolutePath
,
$count
);
return
$result
;
return
$result
;
...
@@ -335,7 +340,7 @@ class View {
...
@@ -335,7 +340,7 @@ class View {
return
false
;
return
false
;
}
}
}
else
{
}
else
{
$hooks
=
(
$this
->
file_exists
(
$path
))
?
array
(
'write'
)
:
array
(
'create'
,
'write'
);
$hooks
=
(
$this
->
file_exists
(
$path
))
?
array
(
'update'
,
'write'
)
:
array
(
'create'
,
'write'
);
return
$this
->
basicOperation
(
'file_put_contents'
,
$path
,
$hooks
,
$data
);
return
$this
->
basicOperation
(
'file_put_contents'
,
$path
,
$hooks
,
$data
);
}
}
}
}
...
@@ -378,6 +383,7 @@ class View {
...
@@ -378,6 +383,7 @@ class View {
)
{
)
{
$path1
=
$this
->
getRelativePath
(
$absolutePath1
);
$path1
=
$this
->
getRelativePath
(
$absolutePath1
);
$path2
=
$this
->
getRelativePath
(
$absolutePath2
);
$path2
=
$this
->
getRelativePath
(
$absolutePath2
);
$exists
=
$this
->
file_exists
(
$path2
);
if
(
$path1
==
null
or
$path2
==
null
)
{
if
(
$path1
==
null
or
$path2
==
null
)
{
return
false
;
return
false
;
...
@@ -385,13 +391,7 @@ class View {
...
@@ -385,13 +391,7 @@ class View {
$run
=
true
;
$run
=
true
;
if
(
$this
->
shouldEmitHooks
()
&&
(
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
// 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
(
$this
->
emit_file_hooks_pre
(
$exists
,
$path2
,
$run
);
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_write
,
array
(
Filesystem
::
signal_param_path
=>
$this
->
getHookPath
(
$path2
),
Filesystem
::
signal_param_run
=>
&
$run
)
);
}
elseif
(
$this
->
shouldEmitHooks
())
{
}
elseif
(
$this
->
shouldEmitHooks
())
{
\OC_Hook
::
emit
(
\OC_Hook
::
emit
(
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_rename
,
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_rename
,
...
@@ -448,13 +448,7 @@ class View {
...
@@ -448,13 +448,7 @@ class View {
if
(
$this
->
shouldEmitHooks
()
&&
(
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
// 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
)));
Updater
::
writeHook
(
array
(
'path'
=>
$this
->
getHookPath
(
$path2
)));
\OC_Hook
::
emit
(
$this
->
emit_file_hooks_post
(
$exists
,
$path2
);
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_post_write
,
array
(
Filesystem
::
signal_param_path
=>
$this
->
getHookPath
(
$path2
),
)
);
}
elseif
(
$this
->
shouldEmitHooks
()
&&
$result
!==
false
)
{
}
elseif
(
$this
->
shouldEmitHooks
()
&&
$result
!==
false
)
{
Updater
::
renameHook
(
array
(
Updater
::
renameHook
(
array
(
'oldpath'
=>
$this
->
getHookPath
(
$path1
),
'oldpath'
=>
$this
->
getHookPath
(
$path1
),
...
@@ -507,26 +501,7 @@ class View {
...
@@ -507,26 +501,7 @@ class View {
Filesystem
::
signal_param_run
=>
&
$run
Filesystem
::
signal_param_run
=>
&
$run
)
)
);
);
if
(
$run
and
!
$exists
)
{
$this
->
emit_file_hooks_pre
(
$exists
,
$path2
,
$run
);
\OC_Hook
::
emit
(
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_create
,
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
)
);
}
}
}
if
(
$run
)
{
if
(
$run
)
{
$mp1
=
$this
->
getMountPoint
(
$path1
.
$postFix1
);
$mp1
=
$this
->
getMountPoint
(
$path1
.
$postFix1
);
...
@@ -566,18 +541,7 @@ class View {
...
@@ -566,18 +541,7 @@ class View {
Filesystem
::
signal_param_newpath
=>
$this
->
getHookPath
(
$path2
)
Filesystem
::
signal_param_newpath
=>
$this
->
getHookPath
(
$path2
)
)
)
);
);
if
(
!
$exists
)
{
$this
->
emit_file_hooks_post
(
$exists
,
$path2
);
\OC_Hook
::
emit
(
Filesystem
::
CLASSNAME
,
Filesystem
::
signal_post_create
,
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
))
);
}
}
return
$result
;
return
$result
;
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib/files/view.php
+
33
−
13
View file @
4481a841
...
@@ -394,13 +394,12 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -394,13 +394,12 @@ class View extends \PHPUnit_Framework_TestCase {
$this
->
assertNull
(
$this
->
hookPath
);
$this
->
assertNull
(
$this
->
hookPath
);
$subView
->
file_put_contents
(
'/foo.txt'
,
'asd'
);
$subView
->
file_put_contents
(
'/foo.txt'
,
'asd'
);
$this
->
assertNotNull
(
$this
->
hookPath
);
$this
->
assertEquals
(
'/substorage/foo.txt'
,
$this
->
hookPath
);
$this
->
assertEquals
(
'/substorage/foo.txt'
,
$this
->
hookPath
);
}
}
private
$hookPath
;
private
$hookPath
;
function
dummyHook
(
$params
)
{
public
function
dummyHook
(
$params
)
{
$this
->
hookPath
=
$params
[
'path'
];
$this
->
hookPath
=
$params
[
'path'
];
}
}
...
@@ -442,12 +441,6 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -442,12 +441,6 @@ class View extends \PHPUnit_Framework_TestCase {
return
$storage
;
return
$storage
;
}
}
private
$createHookPath
;
function
dummyCreateHook
(
$params
)
{
$this
->
createHookPath
=
$params
[
'path'
];
}
/**
/**
* @medium
* @medium
*/
*/
...
@@ -466,23 +459,50 @@ class View extends \PHPUnit_Framework_TestCase {
...
@@ -466,23 +459,50 @@ class View extends \PHPUnit_Framework_TestCase {
$this
->
assertNull
(
$this
->
hookPath
);
$this
->
assertNull
(
$this
->
hookPath
);
}
}
private
$hookWritePath
;
private
$hookCreatePath
;
private
$hookUpdatePath
;
public
function
dummyHookWrite
(
$params
)
{
$this
->
hookWritePath
=
$params
[
'path'
];
}
public
function
dummyHookUpdate
(
$params
)
{
$this
->
hookUpdatePath
=
$params
[
'path'
];
}
public
function
dummyHookCreate
(
$params
)
{
$this
->
hookCreatePath
=
$params
[
'path'
];
}
public
function
testEditNoCreateHook
()
{
public
function
testEditNoCreateHook
()
{
$storage1
=
$this
->
getTestStorage
();
$storage1
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$storage2
=
$this
->
getTestStorage
();
$defaultRoot
=
\OC\Files\Filesystem
::
getRoot
();
$defaultRoot
=
\OC\Files\Filesystem
::
getRoot
();
\OC\Files\Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
\OC\Files\Filesystem
::
mount
(
$storage1
,
array
(),
'/'
);
\OC\Files\Filesystem
::
mount
(
$storage2
,
array
(),
$defaultRoot
);
\OC\Files\Filesystem
::
mount
(
$storage2
,
array
(),
$defaultRoot
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_create'
,
$this
,
'dummyCreateHook'
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_create'
,
$this
,
'dummyHookCreate'
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_update'
,
$this
,
'dummyHookUpdate'
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_write'
,
$this
,
'dummyHookWrite'
);
$view
=
new
\OC\Files\View
(
$defaultRoot
);
$view
=
new
\OC\Files\View
(
$defaultRoot
);
$this
->
hookPath
=
null
;
$this
->
hook
WritePath
=
$this
->
hookUpdatePath
=
$this
->
hookCreate
Path
=
null
;
$view
->
file_put_contents
(
'/asd.txt'
,
'foo'
);
$view
->
file_put_contents
(
'/asd.txt'
,
'foo'
);
$this
->
assertEquals
(
'/asd.txt'
,
$this
->
createHookPath
);
$this
->
assertEquals
(
'/asd.txt'
,
$this
->
hookCreatePath
);
$this
->
createHookPath
=
null
;
$this
->
assertNull
(
$this
->
hookUpdatePath
);
$this
->
assertEquals
(
'/asd.txt'
,
$this
->
hookWritePath
);
$this
->
hookWritePath
=
$this
->
hookUpdatePath
=
$this
->
hookCreatePath
=
null
;
$view
->
file_put_contents
(
'/asd.txt'
,
'foo'
);
$view
->
file_put_contents
(
'/asd.txt'
,
'foo'
);
$this
->
assertNull
(
$this
->
createHookPath
);
$this
->
assertNull
(
$this
->
hookCreatePath
);
$this
->
assertEquals
(
'/asd.txt'
,
$this
->
hookUpdatePath
);
$this
->
assertEquals
(
'/asd.txt'
,
$this
->
hookWritePath
);
\OC_Hook
::
clear
(
'OC_Filesystem'
,
'post_create'
);
\OC_Hook
::
clear
(
'OC_Filesystem'
,
'post_update'
);
\OC_Hook
::
clear
(
'OC_Filesystem'
,
'post_write'
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment