From 009273bc78d9ab9d1e01c35f1056b17d52d7b58a Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 15 Feb 2006 17:47:53 +0000 Subject: fix a race and prevent unlinking of a file locked by another process in portage_locks.unlockfile() svn path=/main/trunk/; revision=2714 --- pym/portage_locks.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'pym') diff --git a/pym/portage_locks.py b/pym/portage_locks.py index a6e1afe57..7a9b55674 100644 --- a/pym/portage_locks.py +++ b/pym/portage_locks.py @@ -147,10 +147,9 @@ def unlockfile(mytuple): unhardlink_lockfile(lockfilename) return True - if type(lockfilename) == types.StringType and not os.path.exists(lockfilename): + if type(lockfilename) == types.StringType and os.fstat(myfd).st_nlink != 1: portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1) - if (myfd != None) and type(lockfilename) == types.StringType: - os.close(myfd) + os.close(myfd) return False try: @@ -178,9 +177,14 @@ def unlockfile(mytuple): # We can safely delete the file. portage_util.writemsg("Got the lockfile...\n",1) #portage_util.writemsg("Unlinking...\n") - os.unlink(lockfilename) - portage_util.writemsg("Unlinked lockfile...\n",1) - locking_method(myfd,fcntl.LOCK_UN) + if os.fstat(myfd).st_nlink == 1: + os.unlink(lockfilename) + portage_util.writemsg("Unlinked lockfile...\n",1) + locking_method(myfd,fcntl.LOCK_UN) + else: + portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1) + os.close(myfd) + return False except SystemExit, e: raise except Exception, e: -- cgit v1.2.3-1-g7c22