Rev 4946: Revert all of the extension code. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-set-mtime
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 6 22:17:35 GMT 2010
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-set-mtime
------------------------------------------------------------
revno: 4946
revision-id: john at arbash-meinel.com-20100106221710-3shwzqvrfne5mlyi
parent: john at arbash-meinel.com-20100106201842-br168flml2wictjs
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-set-mtime
timestamp: Wed 2010-01-06 16:17:10 -0600
message:
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.
-------------- next part --------------
=== modified file 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/_readdir_pyx.pyx 2010-01-06 17:20:57 +0000
+++ b/bzrlib/_readdir_pyx.pyx 2010-01-06 22:17:10 +0000
@@ -60,10 +60,8 @@
off_t st_size
int st_dev
ino_t st_ino
- time_t st_atime
int st_mtime
int st_ctime
- int fstat(int fd, stat *buf)
int lstat(char *path, stat *buf)
int S_ISDIR(int mode)
int S_ISCHR(int mode)
@@ -79,14 +77,6 @@
int open(char *pathname, int flags, mode_t mode)
-cdef extern from "sys/time.h":
- struct timeval:
- long tv_sec
- long tv_usec
- # atime, mtime
- int futimes(int fd, timeval tv[2])
-
-
cdef extern from 'Python.h':
int PyErr_CheckSignals() except -1
char * PyString_AS_STRING(object)
@@ -390,25 +380,4 @@
return result
-def fset_mtime(f, mtime):
- """See osutils.fset_mtime."""
- cdef int fd
- cdef int retval
- cdef double d_mtime
- cdef timeval tv[2]
- cdef stat st
-
- fd = f.fileno()
- d_mtime = mtime
- tv[1].tv_sec = <int>(d_mtime)
- tv[1].tv_usec = <int>((d_mtime - tv[1].tv_sec) * 1000000.0)
- retval = fstat(fd, &st)
- if retval != 0:
- raise OSError('Failed to fstat()')
- tv[0].tv_sec = st.st_atime
- tv[0].tv_usec = 0
- retval = futimes(fd, tv)
- if retval != 0:
- raise OSError('Failed to futimes()')
-
# vim: tw=79 ai expandtab sw=4 sts=4
=== modified file 'bzrlib/_walkdirs_win32.pyx'
--- a/bzrlib/_walkdirs_win32.pyx 2010-01-06 19:50:50 +0000
+++ b/bzrlib/_walkdirs_win32.pyx 2010-01-06 22:17:10 +0000
@@ -59,12 +59,6 @@
# Wide character functions
DWORD wcslen(WCHAR *)
- int SetFileTime(
- HANDLE hFile, FILETIME *lpCreationTime, FILETIME *lpLastAccessTime,
- FILETIME *lpLastWriteTime)
-
- long _get_osfhandle(int)
-
cdef extern from "Python.h":
WCHAR *PyUnicode_AS_UNICODE(object)
@@ -153,17 +147,6 @@
return (val * 1.0e-7) - 11644473600.0
-cdef FILETIME _timestamp_to_ftime(double timestamp):
- """Convert a time-since-epoch to a FILETIME."""
- cdef __int64 val
- cdef FILETIME result
-
- val = <__int64>((timestamp + 11644473600.0) * 1.0e7)
- result.dwHighDateTime = <DWORD>(val >> 32)
- result.dwLowDateTime = <DWORD>(val & 0xFFFFFFFF)
- return result
-
-
cdef int _should_skip(WIN32_FIND_DATAW *data):
"""Is this '.' or '..' so we should skip it?"""
if (data.cFileName[0] != c'.'):
@@ -267,18 +250,3 @@
# earlier Exception, so for now, I'm ignoring this
dirblock.sort(key=operator.itemgetter(1))
return dirblock
-
-
-def fset_mtime(f, mtime):
- """See osutils.fset_mtime."""
- cdef HANDLE the_handle
- cdef FILETIME ft
- cdef int retval
-
- ft = _timestamp_to_ftime(mtime)
- the_handle = <HANDLE>(_get_osfhandle(f.fileno()))
- if the_handle == <HANDLE>(-1):
- raise OSError('Invalid fileno') # IOError?
- retval = SetFileTime(the_handle, NULL, NULL, &ft)
- if retval == 0:
- raise WindowsError(GetLastError(), "Failed to set file modified time")
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2010-01-06 18:15:17 +0000
+++ b/bzrlib/osutils.py 2010-01-06 22:17:10 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -1889,39 +1889,6 @@
return b
-def _utime_fset_mtime(f, mtime):
- """Use 'os.utime' to set the mtime.
-
- This will cause a second lookup of the path, etc, but it works.
- :seealso: fset_mtime
- """
- os.utime(f.name, (mtime, mtime))
-
-
-_set_mtime_func = None
-def fset_mtime(f, mtime):
- """Set the last-modified time (mtime) for this file handle.
-
- :param f: A File object (from open()).
- :param mtime: time-since-epoch to set the mtime to. (same as time.time(),
- or st.st_mtime, etc.). This can be a floating point number, but we
- don't guarantee better than 1s resolution.
- :return: None
- """
- global _set_mtime_func
- if _set_mtime_func is None:
- try:
- if sys.platform == "win32":
- from bzrlib._walkdirs_win32 import fset_mtime
- else:
- from bzrlib._readdir_pyx import fset_mtime
- except ImportError:
- _set_mtime_func = _utime_fset_mtime
- else:
- _set_mtime_func = fset_mtime
- return _set_mtime_func(f, mtime)
-
-
def send_all(socket, bytes, report_activity=None):
"""Send all bytes on a socket.
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2010-01-06 20:17:57 +0000
+++ b/bzrlib/tests/test_osutils.py 2010-01-06 22:17:10 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -2004,29 +2004,3 @@
del os.environ['COLUMNS']
# Whatever the result is, if we don't raise an exception, it's ok.
osutils.terminal_width()
-
-
-class TestFSetMtime(tests.TestCaseInTempDir):
-
- def _check_fset_mtime(self, func):
- f = open('test', 'wb')
- try:
- mtime = os.fstat(f.fileno()).st_mtime
- new_mtime = mtime - 20
- func(f, new_mtime)
- finally:
- f.close()
- self.assertNotEqual(mtime, new_mtime)
- set_mtime = os.lstat('test').st_mtime
- # We don't guarantee any better than 2s resolution, due to timestamp
- # precision limitations on older filesystems such as FAT, but try to
- # use functions that have at least microsecond resolution (1us on
- # POSIX, 100ns on Windows)
- self.assertTrue(abs(set_mtime - new_mtime) < 2.0,
- "%r != %r within two seconds" % (new_mtime, set_mtime))
-
- def test_fset_mtime(self):
- self._check_fset_mtime(osutils.fset_mtime)
-
- def test__utime_fset_mtime(self):
- self._check_fset_mtime(osutils._utime_fset_mtime)
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2010-01-06 17:20:57 +0000
+++ b/bzrlib/transform.py 2010-01-06 22:17:10 +0000
@@ -1133,13 +1133,9 @@
raise
f.writelines(contents)
- # We have to flush before calling _set_mtime, otherwise buffered
- # data can be written after we force the mtime. This shouldn't have
- # a huge performance impact, because 'close()' will flush anyway
- f.flush()
- self._set_mtime(f)
finally:
f.close()
+ self._set_mtime(name)
self._set_mode(trans_id, mode_id, S_ISREG)
def _read_file_chunks(self, trans_id):
@@ -1152,14 +1148,14 @@
def _read_symlink_target(self, trans_id):
return os.readlink(self._limbo_name(trans_id))
- def _set_mtime(self, f):
+ def _set_mtime(self, path):
"""All files that are created get the same mtime.
This time is set by the first object to be created.
"""
if self._creation_mtime is None:
self._creation_mtime = time.time()
- osutils.fset_mtime(f, self._creation_mtime)
+ os.utime(path, (self._creation_mtime, self._creation_mtime))
def create_hardlink(self, path, trans_id):
"""Schedule creation of a hard link"""
More information about the bazaar-commits
mailing list