Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
086285fa
Commit
086285fa
authored
Sep 19, 2018
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testnode: properly support deletion of chmod'ed files
/reviewed-on
nexedi/erp5!748
parent
70653d64
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
20 deletions
+40
-20
erp5/tests/testERP5TestNode.py
erp5/tests/testERP5TestNode.py
+19
-5
erp5/util/testnode/Utils.py
erp5/util/testnode/Utils.py
+21
-15
No files found.
erp5/tests/testERP5TestNode.py
View file @
086285fa
...
...
@@ -489,21 +489,35 @@ shared = true
test_node
.
purgeOldTestSuite
(
test_suite_data
)
self
.
assertEquals
([
'foo'
],
os
.
listdir
(
self
.
working_directory
))
def
test_purgeOldTestSuiteChmod
(
self
):
def
test_purgeOldTestSuiteChmod
NonWriteable
(
self
):
"""Old test suites can be deleted even when some files/directories have
been chmod'd to make
read only.
"""
been chmod'd to make
non-writeable
"""
test_node
=
self
.
getTestNode
()
test_suite_data
=
self
.
getTestSuiteData
(
add_third_repository
=
True
)
os
.
mkdir
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
))
non_writable_file
=
open
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
,
'non-writable-file'
),
'w'
)
non_writable_file
.
close
()
# make this file and directory non writeable
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
,
'non-writable-file'
),
0o
000
)
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
),
0o
000
)
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
,
'non-writable-file'
),
0o
400
)
# -r--------
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
),
0o
500
)
# dr-x------
test_node
.
purgeOldTestSuite
(
test_suite_data
)
# should not fail
self
.
assertEqual
([],
os
.
listdir
(
self
.
working_directory
))
def
test_purgeOldTestSuiteChmodNonWriteableNonReadable
(
self
):
"""Old test suites can be deleted even when some files/directories have
been chmod'd to make them non readable and non writeable. """
test_node
=
self
.
getTestNode
()
test_suite_data
=
self
.
getTestSuiteData
(
add_third_repository
=
True
)
os
.
mkdir
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
))
non_writable_file
=
open
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
,
'non-writable-file'
),
'w'
)
non_writable_file
.
close
()
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
,
'non-writable-file'
),
0o000
)
# ----------
os
.
chmod
(
os
.
path
.
join
(
self
.
working_directory
,
'bar'
),
0o000
)
# d---------
test_node
.
purgeOldTestSuite
(
test_suite_data
)
# should not fail
self
.
assertEqual
([],
os
.
listdir
(
self
.
working_directory
))
def
test_09_runTestSuite
(
self
,
my_test_type
=
'UnitTest'
):
"""
...
...
erp5/util/testnode/Utils.py
View file @
086285fa
import
os
import
stat
import
shutil
import
errno
def
rmtree
(
path
):
"""Delete a path recursively.
Like shutil.rmtree, but supporting the case that some files or folder
might have been marked read only. """
def
chmod_retry
(
func
,
path
,
_
):
"""Make sure the
file is writeable / the directory is execu
table.
def
chmod_retry
(
func
,
failed_path
,
exc_info
):
"""Make sure the
directories are executable and wri
table.
"""
if
not
os
.
path
.
exists
(
path
):
e
=
exc_info
[
1
]
if
isinstance
(
e
,
OSError
):
if
e
.
errno
==
errno
.
ENOENT
:
# because we are calling again rmtree on listdir errors, this path might
# have been already deleted by the recursive call to rmtree.
return
os
.
chmod
(
path
,
0o777
)
if
e
.
errno
==
errno
.
EACCES
:
if
func
is
os
.
listdir
:
os
.
chmod
(
failed_path
,
0o700
)
# corner case to handle errors in listing directories.
# https://bugs.python.org/issue8523
# This might raises MaxRecursionError when the directory cannot be listed
# for other reasons than "user does not have read permssion"
return
shutil
.
rmtree
(
path
,
onerror
=
chmod_retry
)
func
(
path
)
shutil
.
rmtree
(
path
,
onerror
=
chmod_retry
)
return
shutil
.
rmtree
(
failed_path
,
onerror
=
chmod_retry
)
# If parent directory is not writable, we still cannot delete the file.
# But make sure not to change the parent of the folder we are deleting.
if
failed_path
!=
path
:
os
.
chmod
(
os
.
path
.
dirname
(
failed_path
),
0o700
)
return
func
(
failed_path
)
raise
shutil
.
rmtree
(
path
,
onerror
=
chmod_retry
)
def
createFolder
(
folder
,
clean
=
False
):
if
os
.
path
.
exists
(
folder
):
...
...
Write
Preview
Markdown
is supported
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