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
75a871ec
Commit
75a871ec
authored
12 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
expire all operation no longer needed; delete oldest versions if limit of empty space is reached
parent
a7bb4b12
No related branches found
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_versions/ajax/expireAll.php
+0
-44
0 additions, 44 deletions
apps/files_versions/ajax/expireAll.php
apps/files_versions/lib/versions.php
+30
-25
30 additions, 25 deletions
apps/files_versions/lib/versions.php
with
30 additions
and
69 deletions
apps/files_versions/ajax/expireAll.php
deleted
100644 → 0
+
0
−
44
View file @
a7bb4b12
<?php
/**
* ownCloud - user_migrate
*
* @author Sam Tuke
* @copyright 2012 Sam Tuke samtuke@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// TODO: Allow admins to expire versions of any user
// TODO: Provide feedback as to how many versions were deleted
// Check user and app status
OCP\JSON
::
checkLoggedIn
();
OCP\App
::
checkAppEnabled
(
'files_versions'
);
OCP\JSON
::
callCheck
();
$versions
=
new
OCA_Versions\Storage
();
if
(
$versions
->
expireAll
()
)
{
OCP\JSON
::
success
();
die
();
}
else
{
OCP\JSON
::
error
();
die
();
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/files_versions/lib/versions.php
+
30
−
25
View file @
75a871ec
...
...
@@ -30,12 +30,12 @@ class Storage {
const
DEFAULTMAXFILESIZE
=
10485760
;
// 10MB
const
DEFAULTMAXVERSIONS
=
50
;
var
$MAX_VERSIONS_PER_INTERVAL
=
array
(
1
=>
array
(
'intervalEndsAfter'
=>
3600
,
//first hour, one version every 10sec
'step'
=>
10
),
2
=>
array
(
'intervalEndsAfter'
=>
86400
,
//next 24h, one version every hour
'step'
=>
3600
),
3
=>
array
(
'intervalEndsAfter'
=>
-
1
,
//until the end one version per day
'step'
=>
86400
),
private
static
$max_versions_per_interval
=
array
(
1
=>
array
(
'intervalEndsAfter'
=>
3600
,
//first hour, one version every 10sec
'step'
=>
10
),
2
=>
array
(
'intervalEndsAfter'
=>
86400
,
//next 24h, one version every hour
'step'
=>
3600
),
3
=>
array
(
'intervalEndsAfter'
=>
-
1
,
//until the end one version per day
'step'
=>
86400
),
);
private
static
function
getUidAndFilename
(
$filename
)
...
...
@@ -94,7 +94,7 @@ class Storage {
$matches
=
glob
(
$versionsName
.
'.v*'
);
sort
(
$matches
);
$parts
=
explode
(
'.v'
,
end
(
$matches
));
if
((
end
(
$parts
)
+
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
1
][
'step'
])
>
time
())
{
if
((
end
(
$parts
)
+
Storage
::
$
max_versions_per_interval
[
1
][
'step'
])
>
time
())
{
return
false
;
}
}
...
...
@@ -240,7 +240,7 @@ class Storage {
*/
public
static
function
expire
(
$filename
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$versions_fileview
=
new
\OC_FilesystemView
(
'/'
.
$uid
.
'/files_versions'
);
// get available disk space for user
...
...
@@ -266,43 +266,48 @@ class Storage {
$numOfVersions
=
count
(
$versions
);
$interval
=
1
;
$step
=
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'step'
];
if
(
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'intervalEndsAfter'
]
==
-
1
)
{
$step
=
Storage
::
$
max_versions_per_interval
[
$interval
][
'step'
];
if
(
Storage
::
$
max_versions_per_interval
[
$interval
][
'intervalEndsAfter'
]
==
-
1
)
{
$nextInterval
=
-
1
;
}
else
{
$nextInterval
=
$time
-
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'intervalEndsAfter'
];
$nextInterval
=
$time
-
Storage
::
$
max_versions_per_interval
[
$interval
][
'intervalEndsAfter'
];
}
$nextVersion
=
$versions
[
0
][
'version
s
'
]
-
$step
;
$nextVersion
=
$versions
[
0
][
'version'
]
-
$step
;
for
(
$i
=
1
;
$i
<
$numOfVersions
;
$i
++
)
{
if
(
$nextInterval
==
-
1
||
$versions
[
$i
][
'version'
]
>=
$nextInterval
)
{
if
(
$versions
[
$i
][
'version'
]
>
$nextVersion
)
{
//distance between two version to small, delete version (TODO)
//distance between two version to small, delete version
error_log
(
"next version:"
.
$nextVersion
.
" - version: "
.
$versions
[
$i
][
'version'
]);
error_log
(
"unlink: "
.
$filename
.
'.v'
.
$versions
[
$i
][
'version'
]);
$versions_fileview
->
unlink
(
$filename
.
'.v'
.
$versions
[
$i
][
'version'
]);
$availableSpace
+=
$versions
[
$i
][
'size'
];
}
else
{
$nextVersion
=
$versions
[
$i
][
'version'
]
-
$step
;
}
}
else
{
// time to move on to the next interval
$interval
++
;
$step
=
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'step'
];
$step
=
Storage
::
$
max_versions_per_interval
[
$interval
][
'step'
];
$nextVersion
=
$version
[
$i
][
'version'
]
-
$step
;
if
(
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'intervalEndsAfter'
]
==
-
1
)
{
if
(
Storage
::
$
max_versions_per_interval
[
$interval
][
'intervalEndsAfter'
]
==
-
1
)
{
$nextInterval
=
-
1
;
}
else
{
$nextInterval
=
$time
-
Storage
::
$
MAX_VERSIONS_PER_INTERVAL
[
$interval
][
'intervalEndsAfter'
];
$nextInterval
=
$time
-
Storage
::
$
max_versions_per_interval
[
$interval
][
'intervalEndsAfter'
];
}
}
}
// check if enough space is available after versions are rearranged
$versions
=
array_reverse
(
$versions
);
// oldest version first
$numOfVersions
=
count
(
$versions
);
$i
=
0
;
while
(
$availableSpace
<
0
)
{
$versions_fileview
->
unlink
(
$filename
.
'.v'
.
$versions
[
$i
][
'version'
]);
$availableSpace
+=
$versions
[
$i
][
'size'
];
$i
++
;
if
(
$i
=
$numOfVersions
-
2
)
break
;
// keep at least the last version
}
}
}
/**
* @brief Erase all old versions of all user files
* @return true/false
*/
public
function
expireAll
()
{
$view
=
\OCP\Files
::
getStorage
(
'files_versions'
);
return
$view
->
deleteAll
(
''
,
true
);
}
}
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