def wait_for_file_mtime_change(filename): """This function is typically called before a file save operation, waiting if necessary for the file modification time to change. The purpose is to avoid successive file updates going undetected by the caching mechanism that depends on a change in the file modification time to know when the file should be reparsed.""" from trac.util import touch_file try: mtime = os.stat(filename).st_mtime touch_file(filename) while mtime == os.stat(filename).st_mtime: time.sleep(1e-3) touch_file(filename) except OSError: pass # file doesn't exist (yet)
def test_missing(self): util.touch_file(self.filename) self.assertTrue(os.path.isfile(self.filename)) self.assertEqual(0, os.path.getsize(self.filename))
def test_touch_file(self): util.create_file(self.filename, self.data, 'wb') util.touch_file(self.filename) with open(self.filename, 'rb') as f: self.assertEqual(self.data, f.read())