Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
0868e496
Commit
0868e496
authored
Mar 19, 2015
by
Thomas Müller
Browse files
Merge pull request #14980 from owncloud/fix-fileglobalgc
Fix fileglobalgc unlink parameter warnings
parents
e40b0701
693ca9a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/private/cache/fileglobalgc.php
View file @
0868e496
...
...
@@ -6,6 +6,9 @@ use OC\BackgroundJob\Job;
use
OCP\IConfig
;
class
FileGlobalGC
extends
Job
{
// only do cleanup every 5 minutes
const
CLEANUP_TTL_SEC
=
300
;
public
function
run
(
$argument
)
{
$this
->
gc
(
\
OC
::
$server
->
getConfig
(),
$this
->
getCacheDir
());
}
...
...
@@ -39,8 +42,7 @@ class FileGlobalGC extends Job {
public
function
gc
(
IConfig
$config
,
$cacheDir
)
{
$lastRun
=
$config
->
getAppValue
(
'core'
,
'global_cache_gc_lastrun'
,
0
);
$now
=
time
();
if
((
$now
-
$lastRun
)
<
300
)
{
// only do cleanup every 5 minutes
if
((
$now
-
$lastRun
)
<
self
::
CLEANUP_TTL_SEC
)
{
return
;
}
$config
->
setAppValue
(
'core'
,
'global_cache_gc_lastrun'
,
$now
);
...
...
@@ -48,6 +50,8 @@ class FileGlobalGC extends Job {
return
;
}
$paths
=
$this
->
getExpiredPaths
(
$cacheDir
,
$now
);
array_walk
(
$paths
,
'unlink'
);
array_walk
(
$paths
,
function
(
$file
)
{
unlink
(
$file
);
});
}
}
tests/lib/cache/fileglobalgc.php
View file @
0868e496
...
...
@@ -70,4 +70,38 @@ class FileGlobalGC extends TestCase {
mkdir
(
$this
->
cacheDir
.
'asd'
);
$this
->
assertEquals
([
$this
->
cacheDir
.
'foo'
],
$this
->
gc
->
getExpiredPaths
(
$this
->
cacheDir
,
$time
));
}
public
function
testGcUnlink
()
{
$time
=
time
();
$this
->
addCacheFile
(
'foo'
,
$time
-
10
);
$this
->
addCacheFile
(
'bar'
,
$time
-
10
);
$this
->
addCacheFile
(
'asd'
,
$time
+
10
);
$config
=
$this
->
getMock
(
'\OCP\IConfig'
);
$config
->
expects
(
$this
->
once
())
->
method
(
'getAppValue'
)
->
with
(
'core'
,
'global_cache_gc_lastrun'
,
0
)
->
willReturn
(
$time
-
\
OC\Cache\FileGlobalGC
::
CLEANUP_TTL_SEC
-
1
);
$config
->
expects
(
$this
->
once
())
->
method
(
'setAppValue'
);
$this
->
gc
->
gc
(
$config
,
$this
->
cacheDir
);
$this
->
assertFileNotExists
(
$this
->
cacheDir
.
'foo'
);
$this
->
assertFileNotExists
(
$this
->
cacheDir
.
'bar'
);
$this
->
assertFileExists
(
$this
->
cacheDir
.
'asd'
);
}
public
function
testGcLastRun
()
{
$time
=
time
();
$config
=
$this
->
getMock
(
'\OCP\IConfig'
);
$config
->
expects
(
$this
->
once
())
->
method
(
'getAppValue'
)
->
with
(
'core'
,
'global_cache_gc_lastrun'
,
0
)
->
willReturn
(
$time
);
$config
->
expects
(
$this
->
never
())
->
method
(
'setAppValue'
);
$this
->
gc
->
gc
(
$config
,
$this
->
cacheDir
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment