~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-06 22:17:10 UTC
  • mto: This revision was merged to the branch mainline in revision 4940.
  • Revision ID: john@arbash-meinel.com-20100106221710-3shwzqvrfne5mlyi
Revert all of the extension code.

Instead, just stick with os.utime. It is *much* simpler, and I couldn't
find a performance impact of not using it.
The one small difference is that you should call it after closing
the file, but that is reasonable to do anyway.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1889
1889
    return b
1890
1890
 
1891
1891
 
1892
 
def _utime_fset_mtime(f, mtime):
1893
 
    """Use 'os.utime' to set the mtime.
1894
 
 
1895
 
    This will cause a second lookup of the path, etc, but it works.
1896
 
    :seealso: fset_mtime
1897
 
    """
1898
 
    os.utime(f.name, (mtime, mtime))
1899
 
 
1900
 
 
1901
 
_set_mtime_func = None
1902
 
def fset_mtime(f, mtime):
1903
 
    """Set the last-modified time (mtime) for this file handle.
1904
 
 
1905
 
    :param f: A File object (from open()).
1906
 
    :param mtime: time-since-epoch to set the mtime to. (same as time.time(),
1907
 
        or st.st_mtime, etc.). This can be a floating point number, but we
1908
 
        don't guarantee better than 1s resolution.
1909
 
    :return: None
1910
 
    """
1911
 
    global _set_mtime_func
1912
 
    if _set_mtime_func is None:
1913
 
        try:
1914
 
            if sys.platform == "win32":
1915
 
                from bzrlib._walkdirs_win32 import fset_mtime
1916
 
            else:
1917
 
                from bzrlib._readdir_pyx import fset_mtime
1918
 
        except ImportError:
1919
 
            _set_mtime_func = _utime_fset_mtime
1920
 
        else:
1921
 
            _set_mtime_func = fset_mtime
1922
 
    return _set_mtime_func(f, mtime)
1923
 
 
1924
 
 
1925
1892
def send_all(socket, bytes, report_activity=None):
1926
1893
    """Send all bytes on a socket.
1927
1894