--- /tmp/bintree.py 2013-11-05 04:12:41.138995391 -0500 +++ /usr/lib/portage/pym/portage/dbapi/bintree.py 2013-11-05 04:21:44.098975898 -0500 @@ -939,10 +939,25 @@ if not fcmd: raise EnvironmentError("FETCHCOMMAND is unset") - fd, tmp_filename = tempfile.mkstemp() - tmp_dirname, tmp_basename = os.path.split(tmp_filename) - os.close(fd) - + # old method completely breaks timestamp caching + # make an archive copy of our file (preserves timestamps) + # cd to temp directory + # fetch file + # cd to $cwd so wget analyses the unqualified basename + tmp_dirname = tempfile.mkdtemp() + fetch_cwd = os.getcwd() + os.chdir(tmp_dirname) + tmp_basename = os.path.basename(pkgindex_file) + tmp_filename = os.path.join(tmp_dirname, tmp_basename) + f_pkgindex_file = open(pkgindex_file, 'rb') + f_tmpfile = open(tmp_basename, 'wb') + f_tmpfile.write(f_pkgindex_file.read()) + f_tmpfile.close() + f_pkgindex_file.close() + os.utime(tmp_basename, (int(local_timestamp), int(local_timestamp))) + tmp_stat_original = os.stat(tmp_filename) + fcmd = fcmd.replace('-O "${DISTDIR}/${FILE}"', '-N') + fcmd_vars = { "DISTDIR": tmp_dirname, "FILE": tmp_basename, @@ -957,9 +972,20 @@ success = portage.getbinpkg.file_get( fcmd=fcmd, fcmd_vars=fcmd_vars) + + # return from whence we came, cleanups? + os.chdir(fetch_cwd) + + if tmp_stat_original.st_ctime == os.stat(tmp_filename).st_ctime: + # set to the tmpdir so both are deleted + tmp_filename = tmp_dirname + raise UseCachedCopyOfRemoteIndex() + if not success: raise EnvironmentError("%s failed" % (setting,)) f = open(tmp_filename, 'rb') + # set to the tmpdir so both are deleted + tmp_filename = tmp_dirname f_dec = codecs.iterdecode(f, _encodings['repo.content'], errors='replace')