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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
b712393e
Commit
b712393e
authored
10 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
fix etag propagation
parent
aae22b2d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files_sharing/appinfo/app.php
+0
-2
0 additions, 2 deletions
apps/files_sharing/appinfo/app.php
apps/files_sharing/lib/helper.php
+35
-0
35 additions, 0 deletions
apps/files_sharing/lib/helper.php
apps/files_sharing/lib/updater.php
+33
-44
33 additions, 44 deletions
apps/files_sharing/lib/updater.php
with
68 additions
and
46 deletions
apps/files_sharing/appinfo/app.php
+
0
−
2
View file @
b712393e
...
...
@@ -17,6 +17,4 @@ OCP\Util::addScript('files_sharing', 'share');
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_delete'
,
'\OC\Files\Cache\Shared_Updater'
,
'postDeleteHook'
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'delete'
,
'\OC\Files\Cache\Shared_Updater'
,
'deleteHook'
);
\OC_Hook
::
connect
(
'OC_Filesystem'
,
'post_rename'
,
'\OC\Files\Cache\Shared_Updater'
,
'renameHook'
);
\OC_Hook
::
connect
(
'OCP\Share'
,
'post_shared'
,
'\OC\Files\Cache\Shared_Updater'
,
'shareHook'
);
\OC_Hook
::
connect
(
'OCP\Share'
,
'pre_unshare'
,
'\OC\Files\Cache\Shared_Updater'
,
'shareHook'
);
\OC_Hook
::
connect
(
'OC_Appconfig'
,
'post_set_value'
,
'\OCA\Files\Share\Maintainer'
,
'configChangeHook'
);
This diff is collapsed.
Click to expand it.
apps/files_sharing/lib/helper.php
+
35
−
0
View file @
b712393e
...
...
@@ -111,4 +111,39 @@ class Helper {
}
return
true
;
}
public
static
function
getSharesFromItem
(
$target
)
{
$result
=
array
();
$owner
=
\OC\Files\Filesystem
::
getOwner
(
$target
);
\OC\Files\Filesystem
::
initMountPoints
(
$owner
);
$info
=
\OC\Files\Filesystem
::
getFileInfo
(
$target
);
$ownerView
=
new
\OC\Files\View
(
'/'
.
$owner
.
'/files'
);
if
(
$owner
!=
\OCP\User
::
getUser
()
)
{
$path
=
$ownerView
->
getPath
(
$info
[
'fileid'
]);
}
else
{
$path
=
$target
;
}
$ids
=
array
();
while
(
$path
!==
''
&&
$path
!==
'.'
&&
$path
!==
'/'
)
{
$info
=
$ownerView
->
getFileInfo
(
$path
);
$ids
[]
=
$info
[
'fileid'
];
$path
=
dirname
(
$path
);
}
if
(
!
empty
(
$ids
))
{
$idList
=
array_chunk
(
$ids
,
99
,
true
);
foreach
(
$idList
as
$subList
)
{
$statement
=
"SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN ("
.
implode
(
','
,
$subList
)
.
") AND `share_type` IN (0, 1, 2)"
;
$query
=
\OCP\DB
::
prepare
(
$statement
);
$r
=
$query
->
execute
();
$result
=
array_merge
(
$result
,
$r
->
fetchAll
());
}
}
return
$result
;
}
}
This diff is collapsed.
Click to expand it.
apps/files_sharing/lib/updater.php
+
33
−
44
View file @
b712393e
...
...
@@ -26,31 +26,48 @@ class Shared_Updater {
// shares which can be removed from oc_share after the delete operation was successful
static
private
$toRemove
=
array
();
/**
* @brief walk up the users file tree and update the etags
* @param string $user
* @param string $path
*/
static
private
function
correctUsersFolder
(
$user
,
$path
)
{
// $path points to the mount point which is a virtual folder, so we start with
// the parent
$path
=
'/files'
.
dirname
(
$path
);
\OC\Files\Filesystem
::
initMountPoints
(
$user
);
$view
=
new
\OC\Files\View
(
'/'
.
$user
);
if
(
$view
->
file_exists
(
$path
))
{
while
(
$path
!==
'/'
)
{
$etag
=
$view
->
getETag
(
$path
);
$view
->
putFileInfo
(
$path
,
array
(
'etag'
=>
$etag
));
$path
=
dirname
(
$path
);
}
}
else
{
error_log
(
"error!"
.
'can not update etags on '
.
$path
.
' for user '
.
$user
);
\OCP\Util
::
writeLog
(
'files_sharing'
,
'can not update etags on '
.
$path
.
' for user '
.
$user
,
\OCP\Util
::
ERROR
);
}
}
/**
* Correct the parent folders' ETags for all users shared the file at $target
*
* @param string $target
*/
static
public
function
correctFolders
(
$target
)
{
$uid
=
\OCP\User
::
getUser
();
$uidOwner
=
\OC\Files\Filesystem
::
getOwner
(
$target
);
$info
=
\OC\Files\Filesystem
::
getFileInfo
(
$target
);
$checkedUser
=
array
(
$uidOwner
);
// Correct Shared folders of other users shared with
$users
=
\OCP\Share
::
getUsersItemShared
(
'file'
,
$info
[
'fileid'
],
$uidOwner
,
true
);
if
(
!
empty
(
$users
))
{
while
(
!
empty
(
$users
))
{
$reshareUsers
=
array
();
$shares
=
\OCA\Files_Sharing\Helper
::
getSharesFromItem
(
$target
);
foreach
(
$shares
as
$share
)
{
if
((
int
)
$share
[
'share_type'
]
===
\OCP\Share
::
SHARE_TYPE_USER
)
{
self
::
correctUsersFolder
(
$share
[
'share_with'
],
$share
[
'file_target'
]);
}
elseif
((
int
)
$share
[
'share_type'
]
===
\OCP\Share
::
SHARE_TYPE_GROUP
)
{
$users
=
\OC_Group
::
usersInGroup
(
$share
[
'share_with'
]);
foreach
(
$users
as
$user
)
{
if
(
!
in_array
(
$user
,
$checkedUser
)
)
{
$etag
=
\OC\Files\Filesystem
::
getETag
(
''
);
\OCP\Config
::
setUserValue
(
$user
,
'files_sharing'
,
'etag'
,
$etag
);
// Look for reshares
$reshareUsers
=
array_merge
(
$reshareUsers
,
\OCP\Share
::
getUsersItemShared
(
'file'
,
$info
[
'fileid'
],
$user
,
true
));
$checkedUser
[]
=
$user
;
}
self
::
correctUsersFolder
(
$user
,
$share
[
'file_target'
]);
}
$users
=
$reshareUsers
;
}
else
{
//unique name for group share
self
::
correctUsersFolder
(
$share
[
'share_with'
],
$share
[
'file_target'
]);
}
}
}
...
...
@@ -107,34 +124,6 @@ class Shared_Updater {
self
::
removeShare
(
$params
[
'path'
]);
}
/**
* @param array $params
*/
static
public
function
shareHook
(
$params
)
{
if
(
$params
[
'itemType'
]
===
'file'
||
$params
[
'itemType'
]
===
'folder'
)
{
if
(
isset
(
$params
[
'uidOwner'
]))
{
$uidOwner
=
$params
[
'uidOwner'
];
}
else
{
$uidOwner
=
\OCP\User
::
getUser
();
}
$users
=
\OCP\Share
::
getUsersItemShared
(
$params
[
'itemType'
],
$params
[
'fileSource'
],
$uidOwner
,
true
,
false
);
if
(
!
empty
(
$users
))
{
while
(
!
empty
(
$users
))
{
$reshareUsers
=
array
();
foreach
(
$users
as
$user
)
{
if
(
$user
!==
$uidOwner
)
{
$etag
=
\OC\Files\Filesystem
::
getETag
(
''
);
\OCP\Config
::
setUserValue
(
$user
,
'files_sharing'
,
'etag'
,
$etag
);
// Look for reshares
$reshareUsers
=
array_merge
(
$reshareUsers
,
\OCP\Share
::
getUsersItemShared
(
'file'
,
$params
[
'fileSource'
],
$user
,
true
));
}
}
$users
=
$reshareUsers
;
}
}
}
}
/**
* clean up oc_share table from files which are no longer exists
*
...
...
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