[NEW PATCH] BZ#726630 Use only os.access to check permissions (via gerrit-bot)
Federico Simoncelli
fsimonce at redhat.com
Mon Aug 1 14:18:42 UTC 2011
New patch submitted by Federico Simoncelli (fsimonce at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/733
commit f451c3f44455239fb40872fb878f1698ada743d7
Author: Federico Simoncelli <fsimonce at redhat.com>
Date: Fri Jul 22 14:48:56 2011 +0000
BZ#726630 Use only os.access to check permissions
The old implementation of fileUtils.pathExists was using a flawed
re-implementation of os.access as backup check for files with a NFS
stale handle, the consequence was that accessible files were
reported as non-accessible.
We now use os.stat to refresh the NFS handle and then os.access to
determine weather we can read and write the file.
Change-Id: Ic7b892886416e866178ac88c04cbfb68ed0c055b
diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py
index adbbf4b..c76e097 100644
--- a/vdsm/storage/fileUtils.py
+++ b/vdsm/storage/fileUtils.py
@@ -182,24 +182,20 @@ def validatePermissions(targetPath):
if st.st_uid != uid or st.st_gid != gid:
raise se.StorageServerAccessPermissionError(targetPath)
-def pathExists(filename, writeable=False):
+def pathExists(filename, writable=False):
# This function is workarround for a NFS issue where
# sometimes os.exists/os.access fails due to NFS stale handle.
- # In such cases we should try again and stat the file
+ try:
+ os.stat(filename)
+ except OSError:
+ return False
+
check = os.R_OK
- if writeable:
- check |= os.W_OK
- if os.access(filename, check):
- return True
+ if writable:
+ check |= os.W_OK
- try:
- s = os.stat(filename)
- if check & s[0] == check:
- return True
- except OSError:
- pass
- return False
+ return os.access(filename, check)
def cleanupfiles(filelist):
"""
More information about the vdsm-patches
mailing list