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
0182a503
Commit
0182a503
authored
11 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
expire trash bin if trash bin exceeds max size after a new file was added to ownCloud
parent
a00cff7c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_trashbin/lib/hooks.php
+4
-0
4 additions, 0 deletions
apps/files_trashbin/lib/hooks.php
apps/files_trashbin/lib/trash.php
+30
-7
30 additions, 7 deletions
apps/files_trashbin/lib/trash.php
with
34 additions
and
7 deletions
apps/files_trashbin/lib/hooks.php
+
4
−
0
View file @
0182a503
...
...
@@ -56,4 +56,8 @@ class Hooks {
Trashbin
::
deleteUser
(
$uid
);
}
}
public
static
function
post_write_hook
(
$params
)
{
Trashbin
::
resizeTrash
(
\OCP\User
::
getUser
());
}
}
This diff is collapsed.
Click to expand it.
apps/files_trashbin/lib/trash.php
+
30
−
7
View file @
0182a503
...
...
@@ -105,8 +105,8 @@ class Trashbin {
\OCP\Util
::
emitHook
(
'\OCA\Files_Trashbin\Trashbin'
,
'post_moveToTrash'
,
array
(
'filePath'
=>
\OC\Files\Filesystem
::
normalizePath
(
$file_path
),
'trashPath'
=>
\OC\Files\Filesystem
::
normalizePath
(
$filename
.
'.d'
.
$timestamp
)));
$trashbinSize
+=
self
::
retainVersions
(
$view
,
$file_path
,
$filename
,
$timestamp
);
$trashbinSize
+=
self
::
retainEncryptionKeys
(
$view
,
$file_path
,
$filename
,
$timestamp
);
$trashbinSize
+=
self
::
retainVersions
(
$file_path
,
$filename
,
$timestamp
);
$trashbinSize
+=
self
::
retainEncryptionKeys
(
$file_path
,
$filename
,
$timestamp
);
}
else
{
\OC_Log
::
write
(
'files_trashbin'
,
'Couldn\'t move '
.
$file_path
.
' to the trash bin'
,
\OC_log
::
ERROR
);
}
...
...
@@ -119,14 +119,13 @@ class Trashbin {
/**
* Move file versions to trash so that they can be restored later
*
* @param \OC\Files\View $view
* @param $file_path path to original file
* @param $filename of deleted file
* @param $timestamp when the file was deleted
*
* @return size of stored versions
*/
private
static
function
retainVersions
(
$view
,
$file_path
,
$filename
,
$timestamp
)
{
private
static
function
retainVersions
(
$file_path
,
$filename
,
$timestamp
)
{
$size
=
0
;
if
(
\OCP\App
::
isEnabled
(
'files_versions'
))
{
...
...
@@ -159,14 +158,13 @@ class Trashbin {
/**
* Move encryption keys to trash so that they can be restored later
*
* @param \OC\Files\View $view
* @param $file_path path to original file
* @param $filename of deleted file
* @param $timestamp when the file was deleted
*
* @return size of encryption keys
*/
private
static
function
retainEncryptionKeys
(
$view
,
$file_path
,
$filename
,
$timestamp
)
{
private
static
function
retainEncryptionKeys
(
$file_path
,
$filename
,
$timestamp
)
{
$size
=
0
;
if
(
\OCP\App
::
isEnabled
(
'files_encryption'
))
{
...
...
@@ -670,9 +668,32 @@ class Trashbin {
return
$availableSpace
;
}
/**
* @brief resize trash bin if necessary after a new file was added to ownCloud
* @param string $user user id
*/
public
static
function
resizeTrash
(
$user
)
{
$size
=
self
::
getTrashbinSize
(
$user
);
if
(
$size
===
false
||
$size
<
0
)
{
$size
=
self
::
calculateSize
(
new
\OC\Files\View
(
'/'
.
$user
.
'/files_trashbin'
));
}
$freeSpace
=
self
::
calculateFreeSpace
(
$size
);
if
(
$freeSpace
<
0
)
{
$newSize
=
$size
-
self
::
expire
(
$size
);
if
(
$newSize
!==
$size
)
{
self
::
setTrashbinSize
(
$user
,
$newSize
);
}
}
}
/**
* clean up the trash bin
* @param current size of the trash bin
* @return size of expired files
*/
private
static
function
expire
(
$trashbinSize
)
{
...
...
@@ -839,7 +860,7 @@ class Trashbin {
$result
=
$query
->
execute
(
array
(
$user
))
->
fetchAll
();
if
(
$result
)
{
return
$result
[
0
][
'size'
];
return
(
int
)
$result
[
0
][
'size'
];
}
return
false
;
}
...
...
@@ -867,6 +888,8 @@ class Trashbin {
\OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'delete'
,
"OCA\Files_Trashbin\Hooks"
,
"remove_hook"
);
//Listen to delete user signal
\OCP\Util
::
connectHook
(
'OC_User'
,
'pre_deleteUser'
,
"OCA\Files_Trashbin\Hooks"
,
"deleteUser_hook"
);
//Listen to post write hook
\OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'post_write'
,
"OCA\Files_Trashbin\Hooks"
,
"post_write_hook"
);
}
/**
...
...
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