From f281c83e07a05c32baf782bb9d792435f73003ff Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 24 Dec 2009 04:01:10 +0000 Subject: When integer mtime is desired, use stat_obj[stat.ST_MTIME] instead of the float st_mtime in order to avoid rounding *up* in some rare cases. (trunk r15125) svn path=/main/branches/2.1.7/; revision=15137 --- pym/_emerge/BinpkgFetcher.py | 3 ++- pym/_emerge/actions.py | 2 +- pym/_emerge/main.py | 5 +++-- pym/portage/__init__.py | 4 ++-- pym/portage/cache/flat_hash.py | 2 +- pym/portage/cache/metadata.py | 3 ++- pym/portage/cvstree.py | 3 ++- pym/portage/dbapi/bintree.py | 8 ++++---- pym/portage/dbapi/porttree.py | 2 +- pym/portage/dbapi/vartree.py | 9 +++++---- pym/portage/eclass_cache.py | 3 ++- pym/portage/update.py | 2 +- 12 files changed, 26 insertions(+), 20 deletions(-) diff --git a/pym/_emerge/BinpkgFetcher.py b/pym/_emerge/BinpkgFetcher.py index fbf34df72..bd8b141f3 100644 --- a/pym/_emerge/BinpkgFetcher.py +++ b/pym/_emerge/BinpkgFetcher.py @@ -7,6 +7,7 @@ try: from urllib.parse import urlparse as urllib_parse_urlparse except ImportError: from urlparse import urlparse as urllib_parse_urlparse +import stat import sys import portage from portage import os @@ -115,7 +116,7 @@ class BinpkgFetcher(SpawnProcess): pass else: try: - local_mtime = long(os.stat(self.pkg_path).st_mtime) + local_mtime = os.stat(self.pkg_path)[stat.ST_MTIME] except OSError: pass else: diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index eb777684c..14854c06f 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2390,7 +2390,7 @@ def git_sync_timestamps(settings, portdir): if ec in updated_ec_mtimes: continue ec_path = os.path.join(ec_dir, ec + ".eclass") - current_mtime = long(os.stat(ec_path).st_mtime) + current_mtime = os.stat(ec_path)[stat.ST_MTIME] if current_mtime != ec_mtime: os.utime(ec_path, (ec_mtime, ec_mtime)) updated_ec_mtimes[ec] = ec_mtime diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index b4cd7c5ff..3b1475b53 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -6,6 +6,7 @@ from __future__ import print_function import logging import signal +import stat import sys import textwrap import platform @@ -106,7 +107,7 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): continue inforoot=normpath(root+z) if os.path.isdir(inforoot): - infomtime = long(os.stat(inforoot).st_mtime) + infomtime = os.stat(inforoot)[stat.ST_MTIME] if inforoot not in prev_mtimes or \ prev_mtimes[inforoot] != infomtime: regen_infodirs.append(inforoot) @@ -196,7 +197,7 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): del e #update mtime so we can potentially avoid regenerating. - prev_mtimes[inforoot] = long(os.stat(inforoot).st_mtime) + prev_mtimes[inforoot] = os.stat(inforoot)[stat.ST_MTIME] if badcount: out.eerror("Processed %d info files; %d errors." % \ diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 4846b3ae4..67f68ff8f 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1121,7 +1121,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, for lib_dir in portage.util.unique_array(specials["LDPATH"]+['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']): x = os.path.join(target_root, lib_dir.lstrip(os.sep)) try: - newldpathtime = long(os.stat(x).st_mtime) + newldpathtime = os.stat(x)[stat.ST_MTIME] lib_dirs.add(normalize_path(x)) except OSError as oe: if oe.errno == errno.ENOENT: @@ -9032,7 +9032,7 @@ def _global_updates(trees, prev_mtimes): if len(errors) == 0: # Update our internal mtime since we # processed all of our directives. - timestamps[mykey] = long(mystat.st_mtime) + timestamps[mykey] = mystat[stat.ST_MTIME] else: for msg in errors: writemsg("%s\n" % msg, noiselevel=-1) diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py index 49d7ce6a0..934115805 100644 --- a/pym/portage/cache/flat_hash.py +++ b/pym/portage/cache/flat_hash.py @@ -48,7 +48,7 @@ class database(fs_template.FsBased): if '_mtime_' not in d: # Backward compatibility with old cache # that uses mtime mangling. - d['_mtime_'] = long(_os.fstat(myf.fileno()).st_mtime) + d['_mtime_'] = _os.fstat(myf.fileno())[stat.ST_MTIME] return d finally: myf.close() diff --git a/pym/portage/cache/metadata.py b/pym/portage/cache/metadata.py index 2704bd513..650658afc 100644 --- a/pym/portage/cache/metadata.py +++ b/pym/portage/cache/metadata.py @@ -5,6 +5,7 @@ import errno import re +import stat import sys from portage import os from portage import _encodings @@ -110,7 +111,7 @@ class database(flat_hash.database): except EnvironmentError: pass else: - existing_mtime = long(existing_st.st_mtime) + existing_mtime = existing_st[stat.ST_MTIME] if values['_mtime_'] == existing_mtime and \ existing_content == new_content: return diff --git a/pym/portage/cvstree.py b/pym/portage/cvstree.py index 1f352efeb..ca9d56d2f 100644 --- a/pym/portage/cvstree.py +++ b/pym/portage/cvstree.py @@ -7,6 +7,7 @@ from __future__ import print_function import codecs import re +import stat import sys import time @@ -274,7 +275,7 @@ def getentries(mydir,recursive=0): entries["files"][file]["status"]=["exists"] try: mystat=os.stat(mydir+"/"+file) - mytime = time.asctime(time.gmtime(long(mystat.st_mtime))) + mytime = time.asctime(time.gmtime(mystat[stat.ST_MTIME])) if "status" not in entries["files"][file]: entries["files"][file]["status"]=[] if mytime==entries["files"][file]["date"]: diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index d4039e396..e817e3d03 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -509,7 +509,7 @@ class binarytree(object): match = None for d in possibilities: try: - if long(d["MTIME"]) != long(s.st_mtime): + if long(d["MTIME"]) != s[stat.ST_MTIME]: continue except (KeyError, ValueError): continue @@ -614,7 +614,7 @@ class binarytree(object): d = metadata.get(mycpv, {}) if d: try: - if long(d["MTIME"]) != long(s.st_mtime): + if long(d["MTIME"]) != s[stat.ST_MTIME]: d.clear() except (KeyError, ValueError): d.clear() @@ -627,7 +627,7 @@ class binarytree(object): d["CPV"] = mycpv d["SLOT"] = slot - d["MTIME"] = str(long(s.st_mtime)) + d["MTIME"] = str(s[stat.ST_MTIME]) d["SIZE"] = str(s.st_size) d.update(zip(self._pkgindex_aux_keys, @@ -968,7 +968,7 @@ class binarytree(object): d["CPV"] = cpv st = os.stat(pkg_path) - d["MTIME"] = str(long(st.st_mtime)) + d["MTIME"] = str(st[stat.ST_MTIME]) d["SIZE"] = str(st.st_size) rel_path = self._pkg_paths[cpv] diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 825ca821c..7536f7972 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -672,7 +672,7 @@ class portdbapi(dbapi): mydata["repository"] = self._repository_map.get(mylocation, "") mydata["INHERITED"] = ' '.join(mydata.get("_eclasses_", [])) - mydata["_mtime_"] = long(st.st_mtime) + mydata["_mtime_"] = st[stat.ST_MTIME] eapi = mydata.get("EAPI") if not eapi: diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index f3faa1468..bb2c48a6a 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -51,6 +51,7 @@ from collections import deque import re, shutil, stat, errno, copy, subprocess import logging import os as _os +import stat import sys import time import warnings @@ -233,7 +234,7 @@ class vardbapi(dbapi): if mysplit[0] == '*': mysplit[0] = mysplit[0][1:] try: - mystat = os.stat(self.getpath(mysplit[0]))[stat.ST_MTIME] + mystat = os.stat(self.getpath(mysplit[0])).st_mtime except OSError: mystat = 0 if use_cache and mycp in self.cpcache: @@ -509,7 +510,7 @@ class vardbapi(dbapi): if e.errno != errno.ENOENT: raise raise KeyError(mycpv) - mydir_mtime = long(mydir_stat.st_mtime) + mydir_mtime = mydir_stat[stat.ST_MTIME] pkg_data = self._aux_cache["packages"].get(mycpv) pull_me = cache_these.union(wants) mydata = {"_mtime_" : mydir_mtime} @@ -577,7 +578,7 @@ class vardbapi(dbapi): results = [] for x in wants: if x == "_mtime_": - results.append(long(st.st_mtime)) + results.append(st[stat.ST_MTIME]) continue try: myf = codecs.open( @@ -3123,7 +3124,7 @@ class dblink(object): cfgprot = cfgfiledict["IGNORE"] if not moveme: zing = "---" - mymtime = long(mystat.st_mtime) + mymtime = mystat[stat.ST_MTIME] else: moveme = 1 cfgprot = 1 diff --git a/pym/portage/eclass_cache.py b/pym/portage/eclass_cache.py index 26019400b..39e29d540 100644 --- a/pym/portage/eclass_cache.py +++ b/pym/portage/eclass_cache.py @@ -5,6 +5,7 @@ __all__ = ["cache"] +import stat import sys import warnings from portage.util import normalize_path @@ -95,7 +96,7 @@ class cache(object): if not y.endswith(".eclass"): continue try: - mtime = long(os.stat(os.path.join(x, y)).st_mtime) + mtime = os.stat(os.path.join(x, y))[stat.ST_MTIME] except OSError: continue ys=y[:-eclass_len] diff --git a/pym/portage/update.py b/pym/portage/update.py index 3df7b08f3..b6fa40017 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -122,7 +122,7 @@ def grab_updates(updpath, prev_mtimes=None): file_path = os.path.join(updpath, myfile) mystat = os.stat(file_path) if file_path not in prev_mtimes or \ - long(prev_mtimes[file_path]) != long(mystat.st_mtime): + long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]: content = codecs.open(_unicode_encode(file_path, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace' -- cgit v1.2.3-1-g7c22