Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
07f2fcf7
Commit
07f2fcf7
authored
13 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
add post_* hooks to filesystem for write, create, delete, rename and copy
parent
80257558
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/filesystem.php
+76
-27
76 additions, 27 deletions
lib/filesystem.php
with
76 additions
and
27 deletions
lib/filesystem.php
+
76
−
27
View file @
07f2fcf7
...
@@ -30,10 +30,15 @@
...
@@ -30,10 +30,15 @@
* Hooks provided:
* Hooks provided:
* read(path)
* read(path)
* write(path, &run)
* write(path, &run)
* post_write(path)
* create(path, &run) (when a file is created, both create and write will be emited in that order)
* create(path, &run) (when a file is created, both create and write will be emited in that order)
* post_create(path)
* delete(path, &run)
* delete(path, &run)
* post_delete(path)
* rename(oldpath,newpath, &run)
* rename(oldpath,newpath, &run)
* post_rename(oldpath,newpath)
* copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emited in that order)
* copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emited in that order)
* post_rename(oldpath,newpath)
*
*
* the &run parameter can be set to false to prevent the operation from occuring
* the &run parameter can be set to false to prevent the operation from occuring
*/
*/
...
@@ -231,7 +236,10 @@ class OC_FILESYSTEM{
...
@@ -231,7 +236,10 @@ class OC_FILESYSTEM{
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
return
$storage
->
mkdir
(
self
::
getInternalPath
(
$path
));
$result
=
$storage
->
mkdir
(
self
::
getInternalPath
(
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
@@ -240,7 +248,9 @@ class OC_FILESYSTEM{
...
@@ -240,7 +248,9 @@ class OC_FILESYSTEM{
$run
=
true
;
$run
=
true
;
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'delete'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'delete'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
if
(
$run
){
if
(
$run
){
return
$storage
->
rmdir
(
self
::
getInternalPath
(
$path
));
$result
=
$storage
->
rmdir
(
self
::
getInternalPath
(
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_delete'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
@@ -332,14 +342,20 @@ class OC_FILESYSTEM{
...
@@ -332,14 +342,20 @@ class OC_FILESYSTEM{
static
public
function
file_put_contents
(
$path
,
$data
){
static
public
function
file_put_contents
(
$path
,
$data
){
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
$run
=
true
;
$run
=
true
;
if
(
!
self
::
file_exists
(
$path
)){
$exists
=
self
::
file_exists
(
$path
);
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
return
$storage
->
file_put_contents
(
self
::
getInternalPath
(
$path
),
$data
);
$result
=
$storage
->
file_put_contents
(
self
::
getInternalPath
(
$path
),
$data
);
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
@@ -348,7 +364,9 @@ class OC_FILESYSTEM{
...
@@ -348,7 +364,9 @@ class OC_FILESYSTEM{
$run
=
true
;
$run
=
true
;
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'delete'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'delete'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
if
(
$run
){
if
(
$run
){
return
$storage
->
unlink
(
self
::
getInternalPath
(
$path
));
$result
=
$storage
->
unlink
(
self
::
getInternalPath
(
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_delete'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
@@ -361,14 +379,15 @@ class OC_FILESYSTEM{
...
@@ -361,14 +379,15 @@ class OC_FILESYSTEM{
$mp2
=
self
::
getMountPoint
(
$path2
);
$mp2
=
self
::
getMountPoint
(
$path2
);
if
(
$mp1
==
$mp2
){
if
(
$mp1
==
$mp2
){
if
(
$storage
=
self
::
getStorage
(
$path1
)){
if
(
$storage
=
self
::
getStorage
(
$path1
)){
re
turn
$storage
->
rename
(
self
::
getInternalPath
(
$path1
),
self
::
getInternalPath
(
$path2
));
$
re
sult
=
$storage
->
rename
(
self
::
getInternalPath
(
$path1
),
self
::
getInternalPath
(
$path2
));
}
}
}
elseif
(
$storage1
=
self
::
getStorage
(
$path1
)
and
$storage2
=
self
::
getStorage
(
$path2
)){
}
elseif
(
$storage1
=
self
::
getStorage
(
$path1
)
and
$storage2
=
self
::
getStorage
(
$path2
)){
$tmpFile
=
$storage1
->
toTmpFile
(
self
::
getInternalPath
(
$path1
));
$tmpFile
=
$storage1
->
toTmpFile
(
self
::
getInternalPath
(
$path1
));
$result
=
$storage2
->
fromTmpFile
(
self
::
getInternalPath
(
$path2
));
$result
=
$storage2
->
fromTmpFile
(
self
::
getInternalPath
(
$path2
));
$storage1
->
unlink
(
self
::
getInternalPath
(
$path1
));
$storage1
->
unlink
(
self
::
getInternalPath
(
$path1
));
return
$result
;
}
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_rename'
,
array
(
'oldpath'
=>
$path1
,
'newpath'
=>
$path2
));
return
$result
;
}
}
}
}
}
}
...
@@ -376,7 +395,8 @@ class OC_FILESYSTEM{
...
@@ -376,7 +395,8 @@ class OC_FILESYSTEM{
if
(
self
::
canRead
(
$path1
)
and
self
::
canWrite
(
$path2
)){
if
(
self
::
canRead
(
$path1
)
and
self
::
canWrite
(
$path2
)){
$run
=
true
;
$run
=
true
;
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'copy'
,
array
(
'oldpath'
=>
$path1
,
'newpath'
=>
$path2
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'copy'
,
array
(
'oldpath'
=>
$path1
,
'newpath'
=>
$path2
,
'run'
=>
&
$run
));
if
(
$run
and
!
self
::
file_exists
(
$path2
)){
$exists
=
self
::
file_exists
(
$path2
);
if
(
$run
and
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path2
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path2
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
...
@@ -387,12 +407,18 @@ class OC_FILESYSTEM{
...
@@ -387,12 +407,18 @@ class OC_FILESYSTEM{
$mp2
=
self
::
getMountPoint
(
$path2
);
$mp2
=
self
::
getMountPoint
(
$path2
);
if
(
$mp1
==
$mp2
){
if
(
$mp1
==
$mp2
){
if
(
$storage
=
self
::
getStorage
(
$path1
)){
if
(
$storage
=
self
::
getStorage
(
$path1
)){
re
turn
$storage
->
copy
(
self
::
getInternalPath
(
$path1
),
self
::
getInternalPath
(
$path2
));
$
re
sult
=
$storage
->
copy
(
self
::
getInternalPath
(
$path1
),
self
::
getInternalPath
(
$path2
));
}
}
}
elseif
(
$storage1
=
self
::
getStorage
(
$path1
)
and
$storage2
=
self
::
getStorage
(
$path2
)){
}
elseif
(
$storage1
=
self
::
getStorage
(
$path1
)
and
$storage2
=
self
::
getStorage
(
$path2
)){
$tmpFile
=
$storage1
->
toTmpFile
(
self
::
getInternalPath
(
$path1
));
$tmpFile
=
$storage1
->
toTmpFile
(
self
::
getInternalPath
(
$path1
));
re
turn
$storage2
->
fromTmpFile
(
self
::
getInternalPath
(
$path2
));
$
re
sult
=
$storage2
->
fromTmpFile
(
self
::
getInternalPath
(
$path2
));
}
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_copy'
,
array
(
'oldpath'
=>
$path1
,
'newpath'
=>
$path2
));
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
@@ -401,6 +427,8 @@ class OC_FILESYSTEM{
...
@@ -401,6 +427,8 @@ class OC_FILESYSTEM{
if
(
$allowed
){
if
(
$allowed
){
if
(
$storage
=
self
::
getStorage
(
$path
)){
if
(
$storage
=
self
::
getStorage
(
$path
)){
$run
=
true
;
$run
=
true
;
$exists
=
self
::
file_exists
(
$path
);
$write
=
false
;
switch
(
$mode
){
switch
(
$mode
){
case
'r'
:
case
'r'
:
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'read'
,
array
(
'path'
=>
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'read'
,
array
(
'path'
=>
$path
));
...
@@ -410,26 +438,33 @@ class OC_FILESYSTEM{
...
@@ -410,26 +438,33 @@ class OC_FILESYSTEM{
case
'x+'
:
case
'x+'
:
case
'a+'
:
case
'a+'
:
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'read'
,
array
(
'path'
=>
$path
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'read'
,
array
(
'path'
=>
$path
));
if
(
!
self
::
file_exists
(
$path
)){
$write
=
true
;
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
));
}
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
break
;
break
;
case
'w'
:
case
'w'
:
case
'x'
:
case
'x'
:
case
'a'
:
case
'a'
:
if
(
!
self
::
file_exists
(
$path
)){
$write
=
true
;
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
));
}
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
break
;
break
;
}
}
if
(
$write
){
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
));
}
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
return
$storage
->
fopen
(
self
::
getInternalPath
(
$path
),
$mode
);
$result
=
$storage
->
fopen
(
self
::
getInternalPath
(
$path
),
$mode
);
if
(
$write
){
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
}
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
}
}
return
$result
;
}
}
}
}
}
}
...
@@ -443,28 +478,42 @@ class OC_FILESYSTEM{
...
@@ -443,28 +478,42 @@ class OC_FILESYSTEM{
static
public
function
fromTmpFile
(
$tmpFile
,
$path
){
static
public
function
fromTmpFile
(
$tmpFile
,
$path
){
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
$run
=
true
;
$run
=
true
;
if
(
!
self
::
file_exists
(
$path
)){
$exists
=
self
::
file_exists
(
$path
);
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
return
$storage
->
fromTmpFile
(
$tmpFile
,
self
::
getInternalPath
(
$path
));
$result
=
$storage
->
fromTmpFile
(
$tmpFile
,
self
::
getInternalPath
(
$path
));
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
static
public
function
fromUploadedFile
(
$tmpFile
,
$path
){
static
public
function
fromUploadedFile
(
$tmpFile
,
$path
){
error_log
(
'upload'
);
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
if
(
self
::
canWrite
(
$path
)
and
$storage
=
self
::
getStorage
(
$path
)){
$run
=
true
;
$run
=
true
;
if
(
$run
and
!
self
::
file_exists
(
$path
)){
$exists
=
self
::
file_exists
(
$path
);
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'create'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
if
(
$run
){
if
(
$run
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'write'
,
array
(
'path'
=>
$path
,
'run'
=>
&
$run
));
}
}
error_log
(
'upload2'
);
if
(
$run
){
if
(
$run
){
return
$storage
->
fromUploadedFile
(
$tmpFile
,
self
::
getInternalPath
(
$path
));
$result
=
$storage
->
fromUploadedFile
(
$tmpFile
,
self
::
getInternalPath
(
$path
));
if
(
!
$exists
){
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_create'
,
array
(
'path'
=>
$path
));
}
OC_HOOK
::
emit
(
'OC_FILESYSTEM'
,
'post_write'
,
array
(
'path'
=>
$path
));
return
$result
;
}
}
}
}
}
}
...
...
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