def __exit__(self, exc_type, exc_val, exc_tb): from .. import platform self.fd.close() if exc_type is not None: truncate_and_unlink(self.tmppath) return os.replace(self.tmppath, self.path) platform.sync_dir(os.path.dirname(self.path))
def __enter__(self): from .. import platform try: truncate_and_unlink(self.tmppath) except FileNotFoundError: pass self.fd = platform.SyncFile(self.tmppath, self.binary) return self.fd