*** portage.py.bak Fri Jun 27 14:02:04 2003 --- portage.py Fri Jun 27 15:45:19 2003 *************** *** 208,213 **** --- 208,236 ---- os.kill(0,signal.SIGKILL) sys.exit(1) + def lockfile(filename,verbose=1): + "Locks on /lockdir/filename, creates the lock file if necessary" + lockdir=settings["BUILD_PREFIX"]+"/" + #fd=open(root+lockdir+md5.new(filename).hexdigest(),'w') + fd=open(root+lockdir+filename,'w') + if verbose: + try: + fcntl.lockf(fd,fcntl.LOCK_EX|fcntl.LOCK_NB) + except IOError: + print green(" * ")+"Another process is holding a lock on '"+filename+"'" + print green(" * ")+"Waiting.. ", + sys.stdout.flush() + fcntl.lockf(fd,fcntl.LOCK_EX) + print "Resuming." + else: + fcntl.lockf(fd,fcntl.LOCK_EX) + return fd + + def unlockfile(fd): + "Releases a lock on fd" + fcntl.lockf(fd,fcntl.LOCK_UN) + fd.close() + # dropping the signal handler to gives better tracebacks # enable unless we're debugging if not os.environ.has_key("DEBUG"): *************** *** 1108,1113 **** --- 1131,1137 ---- if listonly: fetched=0 print "" + myfilefd=lockfile(myfile) for loc in filedict[myfile]: if listonly: print loc+" ", *************** *** 1195,1200 **** --- 1219,1225 ---- if not myret: fetched=2 break + unlockfile(myfilefd) if (fetched!=2) and not listonly: print '!!! Couldn\'t download',myfile+". Aborting." return 0