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
f913b162
Commit
f913b162
authored
10 years ago
by
Thomas Müller
Browse files
Options
Downloads
Plain Diff
Merge pull request #9158 from owncloud/no-recursion-on-rmdirr-master
fix recursion on rmdirr
parents
e070e292
fba694ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/helper.php
+11
-6
11 additions, 6 deletions
lib/private/helper.php
tests/lib/helper.php
+24
-0
24 additions, 0 deletions
tests/lib/helper.php
with
35 additions
and
6 deletions
lib/private/helper.php
+
11
−
6
View file @
f913b162
...
...
@@ -405,12 +405,17 @@ class OC_Helper {
*/
static
function
rmdirr
(
$dir
)
{
if
(
is_dir
(
$dir
))
{
$files
=
scandir
(
$dir
);
// FIXME: use flat array instead of recursion to avoid
// too many levels
foreach
(
$files
as
$file
)
{
if
(
$file
!==
''
&&
$file
!==
"."
&&
$file
!==
".."
)
{
self
::
rmdirr
(
"
$dir
/
$file
"
);
$files
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
,
RecursiveDirectoryIterator
::
SKIP_DOTS
),
RecursiveIteratorIterator
::
CHILD_FIRST
);
foreach
(
$files
as
$fileInfo
)
{
/** @var SplFileInfo $fileInfo */
if
(
$fileInfo
->
isDir
())
{
rmdir
(
$fileInfo
->
getRealPath
());
}
else
{
unlink
(
$fileInfo
->
getRealPath
());
}
}
rmdir
(
$dir
);
...
...
This diff is collapsed.
Click to expand it.
tests/lib/helper.php
+
24
−
0
View file @
f913b162
...
...
@@ -454,4 +454,28 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
'http://localhost/owncloud/public.php?service=files'
,
$result
);
}
/**
* Tests recursive folder deletion with rmdirr()
*/
public
function
testRecursiveFolderDeletion
()
{
$baseDir
=
\OC_Helper
::
tmpFolder
()
.
'/'
;
mkdir
(
$baseDir
.
'a/b/c/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a/b/c1/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a/b/c2/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a/b1/c1/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a/b2/c1/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a/b3/c1/d/e'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a1/b'
,
0777
,
true
);
mkdir
(
$baseDir
.
'a1/c'
,
0777
,
true
);
file_put_contents
(
$baseDir
.
'a/test.txt'
,
'Hello file!'
);
file_put_contents
(
$baseDir
.
'a/b1/c1/test one.txt'
,
'Hello file one!'
);
file_put_contents
(
$baseDir
.
'a1/b/test two.txt'
,
'Hello file two!'
);
\OC_Helper
::
rmdirr
(
$baseDir
.
'a'
);
$this
->
assertFalse
(
file_exists
(
$baseDir
.
'a'
));
$this
->
assertTrue
(
file_exists
(
$baseDir
.
'a1'
));
\OC_Helper
::
rmdirr
(
$baseDir
);
$this
->
assertFalse
(
file_exists
(
$baseDir
));
}
}
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