summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-13 01:21:17 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-13 01:21:17 +0000
commitaa3d48fb902f32680e26dc1907ac67971315cf56 (patch)
tree45d3ba6fd616eb83d822398608b98f20deb403bf /pym
parenteab2719aa5dbf539b3525bd576dc3ae7b72fcea8 (diff)
downloadportage-aa3d48fb902f32680e26dc1907ac67971315cf56.tar.gz
portage-aa3d48fb902f32680e26dc1907ac67971315cf56.tar.bz2
portage-aa3d48fb902f32680e26dc1907ac67971315cf56.zip
misc atomic_ofstream and write_atomic updates in portage.py
svn path=/main/trunk/; revision=2703
Diffstat (limited to 'pym')
-rw-r--r--pym/portage.py43
1 files changed, 14 insertions, 29 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 650e831f5..880864c4e 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -92,9 +92,10 @@ try:
portage_uid, portage_gid
import portage_util
- from portage_util import grabdict, grabdict_package, grabfile, grabfile_package, write_atomic, \
+ from portage_util import atomic_ofstream, dump_traceback, getconfig, grabdict, \
+ grabdict_package, grabfile, grabfile_package, \
map_dictlist_vals, pickle_read, pickle_write, stack_dictlist, stack_dicts, stack_lists, \
- unique_array, varexpand, writedict, writemsg, writemsg_stdout, getconfig, dump_traceback
+ unique_array, varexpand, writedict, writemsg, writemsg_stdout, write_atomic
import portage_exception
import portage_gpg
import portage_locks
@@ -600,7 +601,7 @@ def env_update(makelinks=1):
newld=specials["LDPATH"]
if (oldld!=newld):
#ld.so.conf needs updating and ldconfig needs to be run
- myfd=open(root+"etc/ld.so.conf","w")
+ myfd = atomic_ofstream(os.path.join(root, "etc", "ld.so.conf"))
myfd.write("# ld.so.conf autogenerated by env-update; make all changes to\n")
myfd.write("# contents of /etc/env.d directory\n")
for x in specials["LDPATH"]:
@@ -610,7 +611,7 @@ def env_update(makelinks=1):
# Update prelink.conf if we are prelink-enabled
if prelink_capable:
- newprelink=open(root+"etc/prelink.conf","w")
+ newprelink = atomic_ofstream(os.path.join(root, "etc", "prelink.conf"))
newprelink.write("# prelink.conf autogenerated by env-update; make all changes to\n")
newprelink.write("# contents of /etc/env.d directory\n")
@@ -682,7 +683,7 @@ def env_update(makelinks=1):
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile=open(root+"/etc/profile.env","w")
+ outfile = atomic_ofstream(os.path.join(root, "etc", "profile.env"))
outfile.write(penvnotice)
for path in specials.keys():
@@ -706,7 +707,7 @@ def env_update(makelinks=1):
outfile.close()
#create /etc/csh.env for (t)csh support
- outfile=open(root+"/etc/csh.env","w")
+ outfile = atomic_ofstream(os.path.join(root, "etc", "csh.env"))
outfile.write(cenvnotice)
for path in specials.keys():
@@ -4273,10 +4274,7 @@ class vardbapi(dbapi):
if len(myl) == 1:
try:
# Only one package... Counter doesn't matter.
- myf = open(cpath, "w")
- myf.write("1")
- myf.flush()
- myf.close()
+ write_atomic(cpath, "1")
counter = 1
except SystemExit, e:
raise
@@ -4296,13 +4294,8 @@ class vardbapi(dbapi):
else:
counter=long(0)
if corrupted:
- newcpath=cpath+".new"
# update new global counter file
- newcfile=open(newcpath,"w")
- newcfile.write(str(counter))
- newcfile.close()
- # now move global counter file into place
- os.rename(newcpath,cpath)
+ write_atomic(cpath, str(counter))
return counter
def cpv_inject(self,mycpv):
@@ -4310,9 +4303,7 @@ class vardbapi(dbapi):
os.makedirs(self.root+VDB_PATH+"/"+mycpv)
counter=db[self.root]["vartree"].dbapi.counter_tick(self.root,mycpv=mycpv)
# write local package counter so that emerge clean does the right thing
- lcfile=open(self.root+VDB_PATH+"/"+mycpv+"/COUNTER","w")
- lcfile.write(str(counter))
- lcfile.close()
+ write_atomic(os.path.join(self.root, VDB_PATH, mycpv, "COUNTER"), str(counter))
def isInjected(self,mycpv):
if self.cpv_exists(mycpv):
@@ -4389,9 +4380,7 @@ class vardbapi(dbapi):
continue
writemsg("s")
- slotfile=open(origpath+"/SLOT", "w")
- slotfile.write(newslot+"\n")
- slotfile.close()
+ write_atomic(os.path.join(origpath, "SLOT"), newslot+"\n")
def cp_list(self,mycp,use_cache=1):
mysplit=mycp.split("/")
@@ -5343,9 +5332,7 @@ class binarytree(packagetree):
sys.stdout.write("S")
sys.stdout.flush()
- slotfile=open(mytmpdir+"/SLOT", "w")
- slotfile.write(newslot+"\n")
- slotfile.close()
+ write_atomic(os.path.join(mytmpdir, "SLOT"), newslot+"\n")
mytbz2.recompose(mytmpdir, cleanup=1)
return 1
@@ -6848,9 +6835,7 @@ def do_upgrade(mykey):
else:
updating_file=USER_CONFIG_PATH+os.path.sep+x
try:
- myfile=open(updating_file,"w")
- myfile.writelines(file_contents[x])
- myfile.close()
+ write_atomic(updating_file, "".join(file_contents[x]))
except IOError:
continue
@@ -6874,7 +6859,7 @@ def commit_mtimedb():
f = None
try:
mtimedb["version"]=VERSION
- f = portage_util.atomic_ofstream(mymfn)
+ f = atomic_ofstream(mymfn)
cPickle.dump(mtimedb, f, -1)
f.close()
except SystemExit, e: