Eduardo has uploaded a new change for review. Change subject: Fix race in fileUtils.createdir(). ......................................................................
Fix race in fileUtils.createdir(). Checking dir inexistence and creating it afterwards is racy. This version creates the target dir, and if it already existed check if has the requested permissions. Change-Id: Iac856c219a08fa0303e5da1d04f4f6b8e17e07a3 Bug-Id: https://bugzilla.redhat.com/show_bug.cgi?id=838547 Signed-off-by: Eduardo <[email protected]> --- M vdsm/storage/fileUtils.py 1 file changed, 16 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/32/8732/1 diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py index d5cbbe7..c4efe7f 100644 --- a/vdsm/storage/fileUtils.py +++ b/vdsm/storage/fileUtils.py @@ -170,12 +170,24 @@ def createdir(dirPath, mode=None): """ Recursively create directory if doesn't exist + + If already exists check that permissions are as requested. """ - if not os.path.exists(dirPath): - if mode: - os.makedirs(dirPath, mode) + DIR_BIT = 040000 + params = (dirPath, mode) if mode is not None else (dirPath,) + try: + os.makedirs(*params) + except OSError as e: + if e.errno != errno.EEXIST: + raise else: - os.makedirs(dirPath) + log.warning("Dir %s already exists", dirPath) + statinfo = os.stat(dirPath) + if mode is not None and \ + statinfo[stat.ST_MODE] % DIR_BIT - mode % DIR_BIT != 0: + raise OSError(errno.EPERM, + "Existing %s dir permissions %s are not as requested %s" % + (dirPath, oct(statinfo[stat.ST_MODE]), oct(mode))) def resolveUid(user): -- To view, visit http://gerrit.ovirt.org/8732 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iac856c219a08fa0303e5da1d04f4f6b8e17e07a3 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Eduardo <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
