1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Handle race condition in directory creation.

If we try to make a directory, but someone else creates the directory
at the same time as us, we don't need to raise that error to the user.
They asked for the directory to exist, and now it does. This fixes
the race condition which was causing that error to be raised, and
closes #1648.
This commit is contained in:
Matthew Gilliard 2015-07-01 12:07:27 +01:00 committed by Matt Clay
parent f33a8b09a9
commit 17a40aa259

View file

@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import errno
import shutil import shutil
import stat import stat
import grp import grp
@ -280,7 +281,13 @@ def main():
if not os.path.isabs(path): if not os.path.isabs(path):
curpath = curpath.lstrip('/') curpath = curpath.lstrip('/')
if not os.path.exists(curpath): if not os.path.exists(curpath):
os.mkdir(curpath) try:
os.mkdir(curpath)
except OSError, ex:
# Possibly something else created the dir since the os.path.exists
# check above. As long as it's a dir, we don't need to error out.
if not (ex.errno == errno.EEXISTS and os.isdir(curpath)):
raise
tmp_file_args = file_args.copy() tmp_file_args = file_args.copy()
tmp_file_args['path']=curpath tmp_file_args['path']=curpath
changed = module.set_fs_attributes_if_different(tmp_file_args, changed) changed = module.set_fs_attributes_if_different(tmp_file_args, changed)