def test_incremental_write_does_not_set_future_time(self): content = factory.make_bytes() filename = self.make_file(contents=factory.make_string()) # Pretend that this file is older than it is. So that # incrementing its mtime won't put it in the future. old_mtime = os.stat(filename).st_mtime + 10 os.utime(filename, (old_mtime, old_mtime)) incremental_write(content, filename) new_time = time.time() self.assertAlmostEqual(os.stat(filename).st_mtime, new_time, delta=2.0)
def test_incremental_write_updates_modification_time(self): content = factory.make_bytes() filename = self.make_file(contents=factory.make_string()) # Pretend that this file is older than it is. So that # incrementing its mtime won't put it in the future. old_mtime = os.stat(filename).st_mtime - 10 os.utime(filename, (old_mtime, old_mtime)) incremental_write(content, filename) new_time = time.time() # should be much closer to new_time than to old_mtime. self.assertAlmostEqual(os.stat(filename).st_mtime, new_time, delta=2.0)
def write_zone_file(cls, output_file, *parameters): """Write a zone file based on the zone file template. There is a subtlety with zone files: their filesystem timestamp must increase with every rewrite. Some filesystems (ext3?) only seem to support a resolution of one second, and so this method may set an unexpected modification time in order to maintain that property. """ if not isinstance(output_file, list): output_file = [output_file] for outfile in output_file: content = render_dns_template(cls.template_file_name, *parameters) with report_missing_config_dir(): incremental_write(content.encode("utf-8"), outfile, mode=0o644) pass
def test_incremental_write_sets_permissions(self): atomic_file = self.make_file() mode = 0o323 incremental_write(factory.make_bytes(), atomic_file, mode=mode) self.assertEqual(mode, stat.S_IMODE(os.stat(atomic_file).st_mode))