Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
d1d3f4b4
Commit
d1d3f4b4
authored
May 05, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2842 from bcoca/cleanup
generalized cleanup and removed atomic_move return
parents
601c2db1
3ac6c454
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
16 deletions
+9
-16
lib/ansible/module_common.py
+8
-11
library/files/copy
+1
-5
No files found.
lib/ansible/module_common.py
View file @
d1d3f4b4
...
...
@@ -807,9 +807,15 @@ class AnsibleModule(object):
self.fail_json(msg='Could not make backup of
%
s to
%
s:
%
s'
%
(fn, backupdest, e))
return backupdest
def cleanup(tmpfile):
if os.path.exists(tmpfile):
try:
os.unlink(tmpfile)
except OSError, e:
sys.stderr.write("could not cleanup
%
s:
%
s"
%
(tmpfile, e))
def atomic_move(self, src, dest):
'''atomically move src to dest, copying attributes from dest, returns true on success'''
rc = False
context = None
if os.path.exists(dest):
try:
...
...
@@ -829,13 +835,6 @@ class AnsibleModule(object):
dest_file = os.path.basename(dest)
tmp_dest = "
%
s/.
%
s.
%
s.
%
s"
%
(dest_dir,dest_file,os.getpid(),time.time())
def cleanup():
if os.path.exists(tmp_dest):
try:
os.unlink(tmp_dest)
except OSError, e:
sys.stderr.write("could not cleanup
%
s:
%
s"
%
(tmp_dest, e))
try: # leaves tmp file behind when sudo and not root
if os.getenv("SUDO_USER") and os.getuid() != 0:
# cleanup will happen by 'rm' of tempdir
...
...
@@ -848,11 +847,9 @@ class AnsibleModule(object):
if self.selinux_enabled():
# rename might not preserve context
self.set_context_if_different(dest, context, False)
rc = True
except (shutil.Error, OSError, IOError), e:
cleanup()
cleanup(
tmp_dest
)
self.fail_json(msg='Could not replace file:
%
s to
%
s:
%
s'
%
(src, dest, e))
return rc
def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None):
'''
...
...
library/files/copy
View file @
d1d3f4b4
...
...
@@ -147,11 +147,7 @@ def main():
(
rc
,
out
,
err
)
=
module
.
run_command
(
validate
%
src
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
"failed to validate: rc:
%
s error:
%
s"
%
(
rc
,
err
))
if
not
module
.
atomic_move
(
src
,
dest
):
try
:
os
.
unlink
(
src
)
# cleanup tmp files on failure
except
OSError
,
e
:
sys
.
stderr
.
write
(
"failed to clean up tmp file
%
s:
%
s
\n
"
%
(
src
,
e
))
module
.
atomic_move
(
src
,
dest
):
except
IOError
:
module
.
fail_json
(
msg
=
"failed to copy:
%
s to
%
s"
%
(
src
,
dest
))
changed
=
True
...
...
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