* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2012-07-31 23:06 Arfrever Frehtes Taifersar Arahesis
0 siblings, 0 replies; 9+ messages in thread
From: Arfrever Frehtes Taifersar Arahesis @ 2012-07-31 23:06 UTC (permalink / raw
To: gentoo-commits
commit: e9951cc2d1f39af8222d55385d43e0ad1eeb548a
Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org>
AuthorDate: Tue Jul 31 23:02:48 2012 +0000
Commit: Arfrever Frehtes Taifersar Arahesis <arfrever.fta <AT> gmail <DOT> com>
CommitDate: Tue Jul 31 23:02:48 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e9951cc2
Use nanosecond precision in portage.util.movefile.movefile().
---
pym/portage/dbapi/vartree.py | 20 +++++++++++----
pym/portage/util/movefile.py | 55 +++++++++++++++++++++++++++++-------------
2 files changed, 53 insertions(+), 22 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index ea62f6b..08580e8 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -4262,8 +4262,9 @@ class dblink(object):
@type stufftomerge: String or List
@param cfgfiledict: { File:mtime } mapping for config_protected files
@type cfgfiledict: Dictionary
- @param thismtime: The current time (typically long(time.time())
- @type thismtime: Long
+ @param thismtime: None or new mtime for merged files (expressed in seconds
+ in Python <3.3 and nanoseconds in Python >=3.3)
+ @type thismtime: None or Int
@rtype: None or Boolean
@return:
1. True on failure
@@ -4396,7 +4397,10 @@ class dblink(object):
encoding=_encodings['merge'])
if mymtime != None:
showMessage(">>> %s -> %s\n" % (mydest, myto))
- outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
+ if sys.hexversion >= 0x3030000:
+ outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n")
+ else:
+ outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
else:
showMessage(_("!!! Failed to move file.\n"),
level=logging.ERROR, noiselevel=-1)
@@ -4550,7 +4554,10 @@ class dblink(object):
cfgprot = cfgfiledict["IGNORE"]
if not moveme:
zing = "---"
- mymtime = mystat[stat.ST_MTIME]
+ if sys.hexversion >= 0x3030000:
+ mymtime = mystat.st_mtime_ns
+ else:
+ mymtime = mystat[stat.ST_MTIME]
else:
moveme = 1
cfgprot = 1
@@ -4587,7 +4594,10 @@ class dblink(object):
zing = ">>>"
if mymtime != None:
- outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n")
+ if sys.hexversion >= 0x3030000:
+ outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n")
+ else:
+ outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n")
showMessage("%s %s\n" % (zing,mydest))
else:
# we are merging a fifo or device node
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
index 10577b5..b9c4183 100644
--- a/pym/portage/util/movefile.py
+++ b/pym/portage/util/movefile.py
@@ -7,6 +7,7 @@ import errno
import os as _os
import shutil as _shutil
import stat
+import sys
import subprocess
import textwrap
@@ -78,8 +79,9 @@ else:
def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
hardlink_candidates=None, encoding=_encodings['fs']):
"""moves a file from src to dest, preserving all permissions and attributes; mtime will
- be preserved even when moving across filesystems. Returns true on success and false on
- failure. Move is atomic."""
+ be preserved even when moving across filesystems. Returns mtime as integer on success
+ and None on failure. mtime is expressed in seconds in Python <3.3 and nanoseconds in
+ Python >=3.3. Move is atomic."""
if mysettings is None:
mysettings = portage.settings
@@ -265,35 +267,54 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
writemsg("!!! %s\n" % a, noiselevel=-1)
return None # failure
- # Always use stat_obj[stat.ST_MTIME] for the integral timestamp which
- # is returned, since the stat_obj.st_mtime float attribute rounds *up*
+ # In Python <3.3 always use stat_obj[stat.ST_MTIME] for the integral timestamp
+ # which is returned, since the stat_obj.st_mtime float attribute rounds *up*
# if the nanosecond part of the timestamp is 999999881 ns or greater.
try:
if hardlinked:
- newmtime = os.stat(dest)[stat.ST_MTIME]
+ if sys.hexversion >= 0x3030000:
+ newmtime = os.stat(dest).st_mtime_ns
+ else:
+ newmtime = os.stat(dest)[stat.ST_MTIME]
else:
# Note: It is not possible to preserve nanosecond precision
# (supported in POSIX.1-2008 via utimensat) with the IEEE 754
# double precision float which only has a 53 bit significand.
if newmtime is not None:
- os.utime(dest, (newmtime, newmtime))
+ if sys.hexversion >= 0x3030000:
+ os.utime(dest, ns=(newmtime, newmtime))
+ else:
+ os.utime(dest, (newmtime, newmtime))
else:
- newmtime = sstat[stat.ST_MTIME]
+ if sys.hexversion >= 0x3030000:
+ newmtime = sstat.st_mtime_ns
+ else:
+ newmtime = sstat[stat.ST_MTIME]
if renamefailed:
- # If rename succeeded then timestamps are automatically
- # preserved with complete precision because the source
- # and destination inode are the same. Otherwise, round
- # down to the nearest whole second since python's float
- # st_mtime cannot be used to preserve the st_mtim.tv_nsec
- # field with complete precision. Note that we have to use
- # stat_obj[stat.ST_MTIME] here because the float
- # stat_obj.st_mtime rounds *up* sometimes.
- os.utime(dest, (newmtime, newmtime))
+ if sys.hexversion >= 0x3030000:
+ # If rename succeeded then timestamps are automatically
+ # preserved with complete precision because the source
+ # and destination inodes are the same. Otherwise, manually
+ # update timestamps with nanosecond precision.
+ os.utime(dest, ns=(newmtime, newmtime))
+ else:
+ # If rename succeeded then timestamps are automatically
+ # preserved with complete precision because the source
+ # and destination inodes are the same. Otherwise, round
+ # down to the nearest whole second since python's float
+ # st_mtime cannot be used to preserve the st_mtim.tv_nsec
+ # field with complete precision. Note that we have to use
+ # stat_obj[stat.ST_MTIME] here because the float
+ # stat_obj.st_mtime rounds *up* sometimes.
+ os.utime(dest, (newmtime, newmtime))
except OSError:
# The utime can fail here with EPERM even though the move succeeded.
# Instead of failing, use stat to return the mtime if possible.
try:
- newmtime = os.stat(dest)[stat.ST_MTIME]
+ if sys.hexversion >= 0x3030000:
+ newmtime = os.stat(dest).st_mtime_ns
+ else:
+ newmtime = os.stat(dest)[stat.ST_MTIME]
except OSError as e:
writemsg(_("!!! Failed to stat in movefile()\n"), noiselevel=-1)
writemsg("!!! %s\n" % dest, noiselevel=-1)
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2015-04-28 23:42 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2015-04-28 23:42 UTC (permalink / raw
To: gentoo-commits
commit: fb421c04f4754b5cdc1101bd5c64d27c00e5ea8d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 27 02:57:44 2015 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Apr 28 23:40:00 2015 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fb421c04
ro_checker: only check nearest parent (bug 547390)
The ro_checker code added in commit
47ef9a0969474f963dc8e52bfbbb8bc075e8d73c incorrectly asserts that all
parent directories be writable. Fix it to only assert that the nearest
parent directory be writable.
Fixes 47ef9a096947: ("Test for read-only filesystems, fixes bug 378869")
X-Gentoo-Bug: 547390
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=547390
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>
pym/portage/dbapi/vartree.py | 44 +++++++++++++++++++++----------------
pym/portage/util/writeable_check.py | 24 ++++++++++++++++++--
2 files changed, 47 insertions(+), 21 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 1c0deab..c59d778 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -33,7 +33,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util.env_update:env_update',
'portage.util.listdir:dircache,listdir',
'portage.util.movefile:movefile',
- 'portage.util.path:first_existing',
+ 'portage.util.path:first_existing,iter_parents',
'portage.util.writeable_check:get_ro_checker',
'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry',
'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap',
@@ -3325,6 +3325,8 @@ class dblink(object):
showMessage = self._display_merge
stopmerge = False
collisions = []
+ dirs = set()
+ dirs_ro = set()
symlink_collisions = []
destroot = self.settings['ROOT']
showMessage(_(" %s checking %d files for package collisions\n") % \
@@ -3337,6 +3339,18 @@ class dblink(object):
dest_path = normalize_path(
os.path.join(destroot, f.lstrip(os.path.sep)))
+
+ parent = os.path.dirname(dest_path)
+ if parent not in dirs:
+ for x in iter_parents(parent):
+ if x in dirs:
+ break
+ dirs.add(x)
+ if os.path.isdir(x):
+ if not os.access(x, os.W_OK):
+ dirs_ro.add(x)
+ break
+
try:
dest_lstat = os.lstat(dest_path)
except EnvironmentError as e:
@@ -3410,7 +3424,7 @@ class dblink(object):
break
if stopmerge:
collisions.append(f)
- return collisions, symlink_collisions, plib_collisions
+ return collisions, dirs_ro, symlink_collisions, plib_collisions
def _lstat_inode_map(self, path_iter):
"""
@@ -3759,7 +3773,6 @@ class dblink(object):
eagain_error = False
filelist = []
- dirlist = []
linklist = []
paths_with_newlines = []
def onerror(e):
@@ -3792,13 +3805,6 @@ class dblink(object):
unicode_errors.append(new_parent[ed_len:])
break
- relative_path = parent[srcroot_len:]
- if len(relative_path) >= eprefix_len:
- # Files are never installed outside of the prefix,
- # therefore we skip the readonly filesystem check for
- # parent directories of the prefix (see bug 544624).
- dirlist.append(os.path.join(destroot, relative_path))
-
for fname in files:
try:
fname = _unicode_decode(fname,
@@ -3911,9 +3917,17 @@ class dblink(object):
for other in others_in_slot])
prepare_build_dirs(settings=self.settings, cleanup=cleanup)
+ # check for package collisions
+ blockers = self._blockers
+ if blockers is None:
+ blockers = []
+ collisions, dirs_ro, symlink_collisions, plib_collisions = \
+ self._collision_protect(srcroot, destroot,
+ others_in_slot + blockers, filelist, linklist)
+
# Check for read-only filesystems.
ro_checker = get_ro_checker()
- rofilesystems = ro_checker(dirlist)
+ rofilesystems = ro_checker(dirs_ro)
if rofilesystems:
msg = _("One or more files installed to this package are "
@@ -3935,14 +3949,6 @@ class dblink(object):
eerror(msg)
return 1
- # check for package collisions
- blockers = self._blockers
- if blockers is None:
- blockers = []
- collisions, symlink_collisions, plib_collisions = \
- self._collision_protect(srcroot, destroot,
- others_in_slot + blockers, filelist, linklist)
-
if symlink_collisions:
# Symlink collisions need to be distinguished from other types
# of collisions, in order to avoid confusion (see bug #409359).
diff --git a/pym/portage/util/writeable_check.py b/pym/portage/util/writeable_check.py
index 445b2c2..ac6c039 100644
--- a/pym/portage/util/writeable_check.py
+++ b/pym/portage/util/writeable_check.py
@@ -1,5 +1,5 @@
#-*- coding:utf-8 -*-
-# Copyright 2014 Gentoo Foundation
+# Copyright 2014-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
"""
Methods to check whether Portage is going to write to read-only filesystems.
@@ -13,6 +13,7 @@ from __future__ import unicode_literals
import io
import logging
+import os
from portage import _encodings
from portage.util import writemsg_level
@@ -68,7 +69,26 @@ def linux_ro_checker(dir_list):
level=logging.WARNING, noiselevel=-1)
return []
- return set.intersection(ro_filesystems, set(dir_list))
+ ro_devs = {}
+ for x in ro_filesystems:
+ try:
+ ro_devs[os.stat(x).st_dev] = x
+ except OSError:
+ pass
+
+ ro_filesystems.clear()
+ for x in set(dir_list):
+ try:
+ dev = os.stat(x).st_dev
+ except OSError:
+ pass
+ else:
+ try:
+ ro_filesystems.add(ro_devs[dev])
+ except KeyError:
+ pass
+
+ return ro_filesystems
def empty_ro_checker(dir_list):
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2014-01-27 4:02 Chris Reffett
0 siblings, 0 replies; 9+ messages in thread
From: Chris Reffett @ 2014-01-27 4:02 UTC (permalink / raw
To: gentoo-commits
commit: 47ef9a0969474f963dc8e52bfbbb8bc075e8d73c
Author: Chris Reffett <creffett <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 10 14:03:26 2014 +0000
Commit: Chris Reffett <creffett <AT> gentoo <DOT> org>
CommitDate: Mon Jan 27 04:01:35 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=47ef9a09
Test for read-only filesystems, fixes bug 378869
If any read-only filesystems need writing, bail out and display a
useful error message.
v2: Reformat, add a function to return an appropriate read-only checker
for the operating system, so that this can be extended to other OSes.
v3: minor formatting tweaks from bernalex, including use os.path.join()
instead of string concatenation
v4: Update copyright header, change the code in rochecker to open with
io.open in order to not break on non-ascii characters as reported by
Arfrever. Change get_ro_checker to use a dict as suggested by vapier.
v5: Fix comment format as requested by vapier.
v6: Change linux_ro_checker to use set.intersection instead of the
longer check-and-append system as suggested by vapier.
v7: rename rochecker -> writeable_check
---
pym/portage/dbapi/vartree.py | 34 +++++++++++++++-
pym/portage/util/writeable_check.py | 79 +++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index ed62323..7a4a3d2 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2013 Gentoo Foundation
+# Copyright 1998-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import unicode_literals
@@ -32,6 +32,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util.env_update:env_update',
'portage.util.listdir:dircache,listdir',
'portage.util.movefile:movefile',
+ 'portage.util.writeable_check:get_ro_checker',
'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry',
'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap',
'portage.util._async.SchedulerInterface:SchedulerInterface',
@@ -3508,6 +3509,8 @@ class dblink(object):
This function does the following:
+ calls get_ro_checker to retrieve a function for checking whether Portage
+ will write to a read-only filesystem, then runs it against the directory list
calls self._preserve_libs if FEATURES=preserve-libs
calls self._collision_protect if FEATURES=collision-protect
calls doebuild(mydo=pkg_preinst)
@@ -3685,6 +3688,7 @@ class dblink(object):
eagain_error = False
myfilelist = []
+ mydirlist = []
mylinklist = []
paths_with_newlines = []
def onerror(e):
@@ -3717,6 +3721,9 @@ class dblink(object):
unicode_errors.append(new_parent[ed_len:])
break
+ relative_path = parent[srcroot_len:]
+ mydirlist.append(os.path.join("/", relative_path))
+
for fname in files:
try:
fname = _unicode_decode(fname,
@@ -3829,6 +3836,31 @@ class dblink(object):
for other in others_in_slot])
prepare_build_dirs(settings=self.settings, cleanup=cleanup)
+ # Check for read-only filesystems.
+ ro_checker = get_ro_checker()
+ rofilesystems = ro_checker(mydirlist)
+
+ if rofilesystems:
+ msg = _("One or more files installed to this package are "
+ "set to be installed to read-only filesystems. "
+ "Please mount the following filesystems as read-write "
+ "and retry.")
+ msg = textwrap.wrap(msg, 70)
+ msg.append("")
+ for f in rofilesystems:
+ msg.append("\t%s" % os.path.join(destroot,
+ f.lstrip(os.path.sep)))
+ msg.append("")
+ self._elog("eerror", "preinst", msg)
+
+ msg = _("Package '%s' NOT merged due to read-only file systems.") % \
+ self.settings.mycpv
+ msg += _(" If necessary, refer to your elog "
+ "messages for the whole content of the above message.")
+ msg = textwrap.wrap(msg, 70)
+ eerror(msg)
+ return 1
+
# check for package collisions
blockers = self._blockers
if blockers is None:
diff --git a/pym/portage/util/writeable_check.py b/pym/portage/util/writeable_check.py
new file mode 100644
index 0000000..e6ddce6
--- /dev/null
+++ b/pym/portage/util/writeable_check.py
@@ -0,0 +1,79 @@
+#-*- coding:utf-8 -*-
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+"""
+Methods to check whether Portage is going to write to read-only filesystems.
+Since the methods are not portable across different OSes, each OS needs its
+own method. To expand RO checking for different OSes, add a method which
+accepts a list of directories and returns a list of mounts which need to be
+remounted RW, then add "elif ostype == (the ostype value for your OS)" to
+get_ro_checker().
+"""
+from __future__ import unicode_literals
+
+import io
+import logging
+import re
+
+from portage import _encodings
+from portage.util import writemsg_level
+from portage.localization import _
+from portage.data import ostype
+
+
+def get_ro_checker():
+ """
+ Uses the system type to find an appropriate method for testing whether Portage
+ is going to write to any read-only filesystems.
+
+ @return:
+ 1. A method for testing for RO filesystems appropriate to the current system.
+ """
+ return _CHECKERS.get(ostype, empty_ro_checker)
+
+
+def linux_ro_checker(dir_list):
+ """
+ Use /proc/mounts to check that no directories installed by the ebuild are set
+ to be installed to a read-only filesystem.
+
+ @param dir_list: A list of directories installed by the ebuild.
+ @type dir_list: List
+ @return:
+ 1. A list of filesystems which are both set to be written to and are mounted
+ read-only, may be empty.
+ """
+ ro_filesystems = set()
+
+ try:
+ with io.open("/proc/mounts", mode='r', encoding=_encodings['content'],
+ errors='replace') as f:
+ roregex = re.compile(r'(\A|,)ro(\Z|,)')
+ for line in f:
+ if roregex.search(line.split(" ")[3].strip()) is not None:
+ romount = line.split(" ")[1].strip()
+ ro_filesystems.add(romount)
+
+ # If /proc/mounts can't be read, assume that there are no RO
+ # filesystems and return.
+ except EnvironmentError:
+ writemsg_level(_("!!! /proc/mounts cannot be read"),
+ level=logging.WARNING, noiselevel=-1)
+ return []
+
+ return set.intersection(ro_filesystems, set(dir_list))
+
+
+def empty_ro_checker(dir_list):
+ """
+ Always returns [], this is the fallback function if the system does not have
+ an ro_checker method defined.
+ """
+ return []
+
+
+# _CHECKERS is a map from ostype output to the appropriate function to return
+# in get_ro_checker.
+_CHECKERS = {
+ "Linux": linux_ro_checker,
+}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2012-08-02 0:57 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2012-08-02 0:57 UTC (permalink / raw
To: gentoo-commits
commit: e06cb6d66db37ac7ab77acf65038b1f770c13c96
Author: W-Mark Kubacki <wmark <AT> hurrikane <DOT> de>
AuthorDate: Wed Aug 1 17:49:34 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Aug 2 00:51:41 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e06cb6d6
Use If-Modified-Since HTTP-header and avoid downloading a remote index if the local copy is recent enough.
---
pym/portage/dbapi/bintree.py | 24 +++++++++++++++++++--
pym/portage/util/_urlopen.py | 45 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index 9527b07..16ae8ec 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -54,6 +54,11 @@ if sys.hexversion >= 0x3000000:
else:
_unicode = unicode
+class UseCachedCopyOfRemoteIndex(Exception):
+ # If the local copy is recent enough
+ # then fetching the remote index can be skipped.
+ pass
+
class bindbapi(fakedbapi):
_known_keys = frozenset(list(fakedbapi._known_keys) + \
["CHOST", "repository", "USE"])
@@ -852,6 +857,7 @@ class binarytree(object):
if e.errno != errno.ENOENT:
raise
local_timestamp = pkgindex.header.get("TIMESTAMP", None)
+ remote_timestamp = None
rmt_idx = self._new_pkgindex()
proc = None
tmp_filename = None
@@ -861,8 +867,13 @@ class binarytree(object):
# slash, so join manually...
url = base_url.rstrip("/") + "/Packages"
try:
- f = _urlopen(url)
- except IOError:
+ f = _urlopen(url, if_modified_since=local_timestamp)
+ if hasattr(f, 'headers') and f.headers.get('timestamp', ''):
+ remote_timestamp = f.headers.get('timestamp')
+ except IOError as err:
+ if hasattr(err, 'code') and err.code == 304: # not modified (since local_timestamp)
+ raise UseCachedCopyOfRemoteIndex()
+
path = parsed_url.path.rstrip("/") + "/Packages"
if parsed_url.scheme == 'sftp':
@@ -903,7 +914,8 @@ class binarytree(object):
_encodings['repo.content'], errors='replace')
try:
rmt_idx.readHeader(f_dec)
- remote_timestamp = rmt_idx.header.get("TIMESTAMP", None)
+ if not remote_timestamp: # in case it had not been read from HTTP header
+ remote_timestamp = rmt_idx.header.get("TIMESTAMP", None)
if not remote_timestamp:
# no timestamp in the header, something's wrong
pkgindex = None
@@ -931,6 +943,12 @@ class binarytree(object):
writemsg("\n\n!!! %s\n" % \
_("Timed out while closing connection to binhost"),
noiselevel=-1)
+ except UseCachedCopyOfRemoteIndex:
+ writemsg_stdout("\n")
+ writemsg_stdout(
+ colorize("GOOD", _("Local copy of remote index is up-to-date and will be used.")) + \
+ "\n")
+ rmt_idx = pkgindex
except EnvironmentError as e:
writemsg(_("\n\n!!! Error fetching binhost package" \
" info from '%s'\n") % _hide_url_passwd(base_url))
diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py
index 307624b..4296188 100644
--- a/pym/portage/util/_urlopen.py
+++ b/pym/portage/util/_urlopen.py
@@ -2,6 +2,9 @@
# Distributed under the terms of the GNU General Public License v2
import sys
+from datetime import datetime
+from time import mktime
+from email.utils import formatdate, parsedate
try:
from urllib.request import urlopen as _urlopen
@@ -14,15 +17,39 @@ except ImportError:
import urllib2 as urllib_request
from urllib import splituser as urllib_parse_splituser
-def urlopen(url):
+if sys.hexversion >= 0x3000000:
+ long = int
+
+# to account for the difference between TIMESTAMP of the index' contents
+# and the file-'mtime'
+TIMESTAMP_TOLERANCE=5
+
+def urlopen(url, if_modified_since=None):
+ parse_result = urllib_parse.urlparse(url)
try:
- return _urlopen(url)
+ if parse_result.scheme not in ("http", "https"):
+ return _urlopen(url)
+ request = urllib_request.Request(url)
+ request.add_header('User-Agent', 'Gentoo Portage')
+ if if_modified_since:
+ request.add_header('If-Modified-Since', _timestamp_to_http(if_modified_since))
+ opener = urllib_request.build_opener()
+ hdl = opener.open(request)
+ if hdl.headers.get('last-modified', ''):
+ try:
+ add_header = hdl.headers.add_header
+ except AttributeError:
+ # Python 2
+ add_header = hdl.headers.addheader
+ add_header('timestamp', _http_to_timestamp(hdl.headers.get('last-modified')))
+ return hdl
except SystemExit:
raise
- except Exception:
+ except Exception as e:
+ if hasattr(e, 'code') and e.code == 304: # HTTPError 304: not modified
+ raise
if sys.hexversion < 0x3000000:
raise
- parse_result = urllib_parse.urlparse(url)
if parse_result.scheme not in ("http", "https") or \
not parse_result.username:
raise
@@ -40,3 +67,13 @@ def _new_urlopen(url):
auth_handler = urllib_request.HTTPBasicAuthHandler(password_manager)
opener = urllib_request.build_opener(auth_handler)
return opener.open(url)
+
+def _timestamp_to_http(timestamp):
+ dt = datetime.fromtimestamp(float(long(timestamp)+TIMESTAMP_TOLERANCE))
+ stamp = mktime(dt.timetuple())
+ return formatdate(timeval=stamp, localtime=False, usegmt=True)
+
+def _http_to_timestamp(http_datetime_string):
+ tuple = parsedate(http_datetime_string)
+ timestamp = mktime(tuple)
+ return str(long(timestamp))
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2012-05-14 5:03 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2012-05-14 5:03 UTC (permalink / raw
To: gentoo-commits
commit: 2c191d17c5c879c51aeb1c6043d9185b9a5887c0
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon May 14 05:01:51 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May 14 05:01:51 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=2c191d17
binhost: http auth for python3 (bug #413983)
This uses the code from commit 58a8cd1bb943522bc53d02c008ee8eff798bfaaa
as a fallback for python3 when the default urlopen function fails. This
has been tested and is known to work with thttpd password
authentication (it works unencrypted and also when encrypted with
stunnel).
---
pym/portage/dbapi/bintree.py | 5 ++---
pym/portage/util/_urlopen.py | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index 4ac48c9..08fdad0 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -16,6 +16,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util:atomic_ofstream,ensure_dirs,normalize_path,' + \
'writemsg,writemsg_stdout',
'portage.util.listdir:listdir',
+ 'portage.util._urlopen:urlopen@_urlopen',
'portage.versions:best,catpkgsplit,catsplit,_pkg_str',
)
@@ -45,10 +46,8 @@ import warnings
from itertools import chain
try:
from urllib.parse import urlparse
- from urllib.request import urlopen as urllib_request_urlopen
except ImportError:
from urlparse import urlparse
- from urllib import urlopen as urllib_request_urlopen
if sys.hexversion >= 0x3000000:
basestring = str
@@ -845,7 +844,7 @@ class binarytree(object):
# slash, so join manually...
url = base_url.rstrip("/") + "/Packages"
try:
- f = urllib_request_urlopen(url)
+ f = _urlopen(url)
except IOError:
path = parsed_url.path.rstrip("/") + "/Packages"
diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py
new file mode 100644
index 0000000..307624b
--- /dev/null
+++ b/pym/portage/util/_urlopen.py
@@ -0,0 +1,42 @@
+# Copyright 2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import sys
+
+try:
+ from urllib.request import urlopen as _urlopen
+ import urllib.parse as urllib_parse
+ import urllib.request as urllib_request
+ from urllib.parse import splituser as urllib_parse_splituser
+except ImportError:
+ from urllib import urlopen as _urlopen
+ import urlparse as urllib_parse
+ import urllib2 as urllib_request
+ from urllib import splituser as urllib_parse_splituser
+
+def urlopen(url):
+ try:
+ return _urlopen(url)
+ except SystemExit:
+ raise
+ except Exception:
+ if sys.hexversion < 0x3000000:
+ raise
+ parse_result = urllib_parse.urlparse(url)
+ if parse_result.scheme not in ("http", "https") or \
+ not parse_result.username:
+ raise
+
+ return _new_urlopen(url)
+
+def _new_urlopen(url):
+ # This is experimental code for bug #413983.
+ parse_result = urllib_parse.urlparse(url)
+ netloc = urllib_parse_splituser(parse_result.netloc)[1]
+ url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment))
+ password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm()
+ if parse_result.username is not None:
+ password_manager.add_password(None, url, parse_result.username, parse_result.password)
+ auth_handler = urllib_request.HTTPBasicAuthHandler(password_manager)
+ opener = urllib_request.build_opener(auth_handler)
+ return opener.open(url)
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2011-09-15 22:38 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2011-09-15 22:38 UTC (permalink / raw
To: gentoo-commits
commit: 9623d8bfdeee4e2ab728529a86322a26f1b6258e
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Thu Sep 15 22:06:44 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Sep 15 22:32:31 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=9623d8bf
move locking into env_update itself
---
pym/portage/dbapi/vartree.py | 30 +++++++++---------------------
pym/portage/util/env_update.py | 17 ++++++++++++++++-
2 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 4d0a6dd..f146ade 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -1842,16 +1842,10 @@ class dblink(object):
else:
self.settings.pop("PORTAGE_LOG_FILE", None)
- # Lock the config memory file to prevent symlink creation
- # in merge_contents from overlapping with env-update.
- self.vartree.dbapi._fs_lock()
- try:
- env_update(target_root=self.settings['ROOT'],
- prev_mtimes=ldpath_mtimes,
- contents=contents, env=self.settings,
- writemsg_level=self._display_merge)
- finally:
- self.vartree.dbapi._fs_unlock()
+ env_update(target_root=self.settings['ROOT'],
+ prev_mtimes=ldpath_mtimes,
+ contents=contents, env=self.settings,
+ writemsg_level=self._display_merge, vardbapi=self.vartree.dbapi)
return os.EX_OK
@@ -3811,17 +3805,11 @@ class dblink(object):
showMessage(_("!!! FAILED postinst: ")+str(a)+"\n",
level=logging.ERROR, noiselevel=-1)
- # Lock the config memory file to prevent symlink creation
- # in merge_contents from overlapping with env-update.
- self.vartree.dbapi._fs_lock()
- try:
- #update environment settings, library paths. DO NOT change symlinks.
- env_update(
- target_root=self.settings['ROOT'], prev_mtimes=prev_mtimes,
- contents=contents, env=self.settings,
- writemsg_level=self._display_merge)
- finally:
- self.vartree.dbapi._fs_unlock()
+ #update environment settings, library paths. DO NOT change symlinks.
+ env_update(
+ target_root=self.settings['ROOT'], prev_mtimes=prev_mtimes,
+ contents=contents, env=self.settings,
+ writemsg_level=self._display_merge, vardbapi=self.vartree.dbapi)
# For gcc upgrades, preserved libs have to be removed after the
# the library path has been updated.
diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py
index 19c7666..71dcf37 100644
--- a/pym/portage/util/env_update.py
+++ b/pym/portage/util/env_update.py
@@ -19,12 +19,13 @@ from portage.process import find_binary
from portage.util import atomic_ofstream, ensure_dirs, getconfig, \
normalize_path, writemsg
from portage.util.listdir import listdir
+from portage.dbapi.vartree import vartree
if sys.hexversion >= 0x3000000:
long = int
def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
- env=None, writemsg_level=None):
+ env=None, writemsg_level=None, vardbapi=None):
"""
Parse /etc/env.d and use it to generate /etc/profile.env, csh.env,
ld.so.conf, and prelink.conf. Finally, run ldconfig. When ldconfig is
@@ -39,6 +40,20 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
defaults to portage.settings["ROOT"].
@type target_root: String (Path)
"""
+ if vardbapi is None:
+ vardbapi = vartree(settings=portage.settings).dbapi
+
+ # Lock the config memory file to prevent symlink creation
+ # in merge_contents from overlapping with env-update.
+ vardbapi._fs_lock()
+ try:
+ return _env_update(makelinks, target_root, prev_mtimes, contents,
+ env, writemsg_level)
+ finally:
+ vardbapi._fs_unlock()
+
+def _env_update(makelinks, target_root, prev_mtimes, contents, env,
+ writemsg_level):
if writemsg_level is None:
writemsg_level = portage.util.writemsg_level
if target_root is None:
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2011-08-29 16:23 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2011-08-29 16:23 UTC (permalink / raw
To: gentoo-commits
commit: a37eb8ebd2fad3f8074490a061f067e2c637f05d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 29 16:22:17 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 29 16:22:17 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a37eb8eb
env_update: always respect makelinks=False
This ensures that the env-update --no-ldconfig option is always
respected. Also, in order to preserve behavior during downgrades for
an env_update call in vartree.py, remove the makelinks=False for
downgrades since it wasn't respected anyway when lib path mtimes had
changed, and we don't want it to behave differently in this case now
that makelinks=False is always respected. Note that the unconditional
use of the ldconfig -X option (from bug #373341) since commit
e1347f9c0dd5ef5ff1a50d6b136b0648efb8a6ca may also come into play for
downgrades.
---
pym/portage/dbapi/vartree.py | 2 +-
pym/portage/util/env_update.py | 11 ++++-------
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 6281f7e..afcbceb 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -3815,7 +3815,7 @@ class dblink(object):
self.vartree.dbapi._fs_lock()
try:
#update environment settings, library paths. DO NOT change symlinks.
- env_update(makelinks=(not downgrade),
+ env_update(
target_root=self.settings['ROOT'], prev_mtimes=prev_mtimes,
contents=contents, env=self.settings,
writemsg_level=self._display_merge)
diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py
index c670ded..1731663 100644
--- a/pym/portage/util/env_update.py
+++ b/pym/portage/util/env_update.py
@@ -147,7 +147,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
raise
oldld = None
- ld_cache_update=False
+ ldsoconf_update = False
newld = specials["LDPATH"]
if (oldld != newld):
@@ -158,7 +158,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
for x in specials["LDPATH"]:
myfd.write(x + "\n")
myfd.close()
- ld_cache_update=True
+ ldsoconf_update = True
# Update prelink.conf if we are prelink-enabled
if prelink_capable:
@@ -229,11 +229,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
prev_mtimes[x] = newldpathtime
mtime_changed = True
- if mtime_changed:
- ld_cache_update = True
-
if makelinks and \
- not ld_cache_update and \
+ not mtime_changed and \
contents is not None:
libdir_contents_changed = False
for mypath, mydata in contents.items():
@@ -252,7 +249,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
ldconfig = find_binary("%s-ldconfig" % settings["CHOST"])
# Only run ldconfig as needed
- if (ld_cache_update or makelinks) and ldconfig and not eprefix:
+ if makelinks and ldconfig and not eprefix:
# ldconfig has very different behaviour between FreeBSD and Linux
if ostype == "Linux" or ostype.lower().endswith("gnu"):
# We can't update links if we haven't cleaned other versions first, as
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2011-08-29 6:16 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2011-08-29 6:16 UTC (permalink / raw
To: gentoo-commits
commit: 0fb60699ebe51fa998a2d661ecda2c7e021f5d30
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 29 06:12:52 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 29 06:12:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0fb60699
env_update: add minimal EPREFIX support
This takes EPREFIX from the env argument and uses it when joining all
paths. Also, ldconfig calls are disabled when EPREFIX is non-empty,
since it's inappropriate to update the global /etc/ld.so.cache in this
case.
---
pym/portage/dbapi/vartree.py | 4 ++--
pym/portage/util/env_update.py | 22 ++++++++++++++--------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 6e49f38..6281f7e 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -1845,7 +1845,7 @@ class dblink(object):
try:
env_update(target_root=self.settings['ROOT'],
prev_mtimes=ldpath_mtimes,
- contents=contents, env=self.settings.environ(),
+ contents=contents, env=self.settings,
writemsg_level=self._display_merge)
finally:
self.vartree.dbapi._fs_unlock()
@@ -3817,7 +3817,7 @@ class dblink(object):
#update environment settings, library paths. DO NOT change symlinks.
env_update(makelinks=(not downgrade),
target_root=self.settings['ROOT'], prev_mtimes=prev_mtimes,
- contents=contents, env=self.settings.environ(),
+ contents=contents, env=self.settings,
writemsg_level=self._display_merge)
finally:
self.vartree.dbapi._fs_unlock()
diff --git a/pym/portage/util/env_update.py b/pym/portage/util/env_update.py
index eb8a0d9..3dc84d4 100644
--- a/pym/portage/util/env_update.py
+++ b/pym/portage/util/env_update.py
@@ -47,7 +47,10 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
prev_mtimes = portage.mtimedb["ldpath"]
if env is None:
env = os.environ
- envd_dir = os.path.join(target_root, "etc", "env.d")
+
+ eprefix = env.get("EPREFIX", "")
+ eprefix_lstrip = eprefix.lstrip(os.sep)
+ envd_dir = os.path.join(target_root, eprefix_lstrip, "etc", "env.d")
ensure_dirs(envd_dir, mode=0o755)
fns = listdir(envd_dir, EmptyOnError=1)
fns.sort()
@@ -123,7 +126,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
they won't be overwritten by this dict.update call."""
env.update(myconfig)
- ldsoconf_path = os.path.join(target_root, "etc", "ld.so.conf")
+ ldsoconf_path = os.path.join(
+ target_root, eprefix_lstrip, "etc", "ld.so.conf")
try:
myld = io.open(_unicode_encode(ldsoconf_path,
encoding=_encodings['fs'], errors='strict'),
@@ -156,8 +160,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
# Update prelink.conf if we are prelink-enabled
if prelink_capable:
- newprelink = atomic_ofstream(
- os.path.join(target_root, "etc", "prelink.conf"))
+ newprelink = atomic_ofstream(os.path.join(
+ target_root, eprefix_lstrip, "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")
@@ -193,7 +197,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
lib_dirs = set()
for lib_dir in set(specials["LDPATH"] + \
['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']):
- x = os.path.join(target_root, lib_dir.lstrip(os.sep))
+ x = os.path.join(target_root, eprefix_lstrip, lib_dir.lstrip(os.sep))
try:
newldpathtime = os.stat(x)[stat.ST_MTIME]
lib_dirs.add(normalize_path(x))
@@ -246,7 +250,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
ldconfig = find_binary("%s-ldconfig" % env["CHOST"])
# Only run ldconfig as needed
- if (ld_cache_update or makelinks) and ldconfig:
+ if (ld_cache_update or makelinks) and ldconfig and not eprefix:
# ldconfig has very different behaviour between FreeBSD and Linux
if ostype == "Linux" or ostype.lower().endswith("gnu"):
# We can't update links if we haven't cleaned other versions first, as
@@ -272,7 +276,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(target_root, "etc", "profile.env"))
+ outfile = atomic_ofstream(os.path.join(
+ target_root, eprefix_lstrip, "etc", "profile.env"))
outfile.write(penvnotice)
env_keys = [ x for x in env if x != "LDPATH" ]
@@ -286,7 +291,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
outfile.close()
#create /etc/csh.env for (t)csh support
- outfile = atomic_ofstream(os.path.join(target_root, "etc", "csh.env"))
+ outfile = atomic_ofstream(os.path.join(
+ target_root, eprefix_lstrip, "etc", "csh.env"))
outfile.write(cenvnotice)
for x in env_keys:
outfile.write("setenv %s '%s'\n" % (x, env[x]))
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/
@ 2011-05-25 5:43 Zac Medico
0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2011-05-25 5:43 UTC (permalink / raw
To: gentoo-commits
commit: 3f91c71b99e6bdeecf9dcf171769b8a924065af7
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed May 25 05:42:24 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed May 25 05:42:24 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3f91c71b
writedict: use write_atomic for exceptions
Also, fix calling code to handle InvalidLocation exceptions.
---
pym/portage/dbapi/vartree.py | 4 +---
pym/portage/util/__init__.py | 22 ++++++++--------------
2 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 4173283..021191f 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -3726,9 +3726,7 @@ class dblink(object):
cfgfiledict.pop("IGNORE", None)
try:
writedict(cfgfiledict, self.vartree.dbapi._conf_mem_file)
- except IOError as e:
- if e.errno != errno.ENOENT:
- raise
+ except InvalidLocation:
self.settings._init_dirs()
writedict(cfgfiledict, self.vartree.dbapi._conf_mem_file)
diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 0dff25f..94e4451 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -492,20 +492,14 @@ def grablines(myfilename, recursive=0, remember_source_file=False):
def writedict(mydict,myfilename,writekey=True):
"""Writes out a dict to a file; writekey=0 mode doesn't write out
the key and assumes all values are strings, not lists."""
- myfile = None
- try:
- myfile = atomic_ofstream(myfilename)
- if not writekey:
- for x in mydict.values():
- myfile.write(x+"\n")
- else:
- for x in mydict:
- myfile.write("%s %s\n" % (x, " ".join(mydict[x])))
- myfile.close()
- except IOError:
- if myfile is not None:
- myfile.abort()
- raise
+ lines = []
+ if not writekey:
+ for v in mydict.values():
+ lines.append(v + "\n")
+ else:
+ for k, v in mydict.items():
+ lines.append("%s %s\n" % (k, " ".join(v)))
+ write_atomic(myfilename, "".join(lines))
def shlex_split(s):
"""
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-04-28 23:42 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-31 23:06 [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/ Arfrever Frehtes Taifersar Arahesis
-- strict thread matches above, loose matches on Subject: below --
2015-04-28 23:42 Zac Medico
2014-01-27 4:02 Chris Reffett
2012-08-02 0:57 Zac Medico
2012-05-14 5:03 Zac Medico
2011-09-15 22:38 Zac Medico
2011-08-29 16:23 Zac Medico
2011-08-29 6:16 Zac Medico
2011-05-25 5:43 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox