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
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"]:
# 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")
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():
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():
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
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):
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):
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("/")
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
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
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: