summaryrefslogtreecommitdiffstats
path: root/pym/portage/locks.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-03-17 02:23:33 +0000
committerZac Medico <zmedico@gentoo.org>2008-03-17 02:23:33 +0000
commit9cdce048eeb69b68def534168974bfc1c3ff4856 (patch)
tree8f7fee0aee7ced187536b51309235619edee2443 /pym/portage/locks.py
parentf4686ed09e525149fb05d8ca70097ef8f5c0632e (diff)
downloadportage-9cdce048eeb69b68def534168974bfc1c3ff4856.tar.gz
portage-9cdce048eeb69b68def534168974bfc1c3ff4856.tar.bz2
portage-9cdce048eeb69b68def534168974bfc1c3ff4856.zip
Bug #212882 - For compatibility with ENOENT exceptions raised from
fstat calls with CIFS, wrap fstat calls with an appropriate exception handler. svn path=/main/trunk/; revision=9474
Diffstat (limited to 'pym/portage/locks.py')
-rw-r--r--pym/portage/locks.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/pym/portage/locks.py b/pym/portage/locks.py
index e9cc63d36..c6d22c1c5 100644
--- a/pym/portage/locks.py
+++ b/pym/portage/locks.py
@@ -107,7 +107,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
if type(lockfilename) == types.StringType and \
- myfd != HARDLINK_FD and os.fstat(myfd).st_nlink == 0:
+ myfd != HARDLINK_FD and _fstat_nlink(myfd) == 0:
# The file was deleted on us... Keep trying to make one...
os.close(myfd)
writemsg("lockfile recurse\n",1)
@@ -118,6 +118,22 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
return (lockfilename,myfd,unlinkfile,locking_method)
+def _fstat_nlink(fd):
+ """
+ @param fd: an open file descriptor
+ @type fd: Integer
+ @rtype: Integer
+ @return: the current number of hardlinks to the file
+ """
+ try:
+ return os.fstat(fd).st_nlink
+ except EnvironmentError, e:
+ if e.errno == errno.ENOENT:
+ # Some filesystems such as CIFS return
+ # ENOENT which means st_nlink == 0.
+ return 0
+ raise
+
def unlockfile(mytuple):
import fcntl
@@ -163,7 +179,7 @@ def unlockfile(mytuple):
# We won the lock, so there isn't competition for it.
# We can safely delete the file.
writemsg("Got the lockfile...\n",1)
- if os.fstat(myfd).st_nlink == 1:
+ if _fstat_nlink(myfd) == 1:
os.unlink(lockfilename)
writemsg("Unlinked lockfile...\n",1)
locking_method(myfd,fcntl.LOCK_UN)