New patch submitted by Federico Simoncelli (fsimonce(a)redhat.com)
You can review this change at:
http://gerrit.usersys.redhat.com/733
commit 296dd556ea6cb51301a305971e2f5a1566d9f93a
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jul 22 14:48:56 2011 +0000
BZ#XXXXXX Use only os.access to check permissions
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):
"""