Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.buildout
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.buildout
Commits
0a2d0d4a
Commit
0a2d0d4a
authored
Jan 31, 2012
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make buildout.rmtree working with symlink as a path argument.
ref
https://bugs.launchpad.net/zc.buildout/+bug/144228
.
parent
a5d8c3a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
2 deletions
+41
-2
src/zc/buildout/rmtree.py
src/zc/buildout/rmtree.py
+41
-2
No files found.
src/zc/buildout/rmtree.py
View file @
0a2d0d4a
...
...
@@ -24,6 +24,8 @@ def rmtree (path):
read only file.
This tries to chmod the file to writeable and retries before giving up.
Also it tries to remove symlink itself if a symlink as passed as
path argument.
>>> from tempfile import mkdtemp
Let's make a directory ...
...
...
@@ -39,6 +41,8 @@ def rmtree (path):
>>> foo = os.path.join (d, 'foo')
>>> open (foo, 'w').write ('huhu')
>>> bar = os.path.join (d, 'bar')
>>> os.symlink(bar, bar)
and make it unwriteable
...
...
@@ -50,12 +54,47 @@ def rmtree (path):
and now the directory is gone
>>> os.path.isdir (d)
0
Let's make a directory ...
>>> d = mkdtemp()
and make sure it is actually there
>>> os.path.isdir (d)
1
Now create a broken symlink ...
>>> foo = os.path.join (d, 'foo')
>>> os.symlink(foo + '.not_exist', foo)
rmtree should be able to remove it:
>>> rmtree (foo)
and now the directory is gone
>>> os.path.isdir (foo)
0
cleanup directory
>>> rmtree (d)
and now the directory is gone
>>> os.path.isdir (d)
0
"""
def
retry_writeable
(
func
,
path
,
exc
):
os
.
chmod
(
path
,
0600
)
func
(
path
)
if
func
==
os
.
path
.
islink
:
os
.
unlink
(
path
)
else
:
os
.
chmod
(
path
,
0600
)
func
(
path
)
shutil
.
rmtree
(
path
,
onerror
=
retry_writeable
)
...
...
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