(self, filename: PATH_TYPES, **kw: Any)
Rewrite a file atomically.

        Clients are allowed to delete the tmpfile to signal that they don't
        want to have it updated.
Rewrite a file atomically.
Rewrite a file atomically .
def update_safe(self, filename: PATH_TYPES, **kw: Any) -> Generator[IO, None, None]:
        """Rewrite a file atomically.

        Clients are allowed to delete the tmpfile to signal that they don't
        want to have it updated.

        """
        with tempfile.NamedTemporaryFile(
            dir=os.path.dirname(filename),
            delete=False,
            prefix=f"{os.path.basename(filename)}.",
            **kw,
        ) as tf:
            if self.exists(filename):
                os.chmod(tf.name, os.stat(filename).st_mode & 0o7777)
            tf.has_changed = False  # type: ignore
            yield tf
            if not self.exists(tf.name):
                return
            filename_tmp = tf.name
        if self.exists(filename) and self.compare_files(filename, filename_tmp):
            logger.debug(f"File not changed...deleting temporary file: {filename_tmp}")
            os.unlink(filename_tmp)
        else:
            logger.debug(f"Modifying destination: {filename!s} with: {filename_tmp}")
            self.move_file(filename_tmp, filename)
def update_safe ( self , filename : PATH_TYPES , * * kw : Any ) -> Generator [ IO , None , None ] : with tempfile . NamedTemporaryFile ( dir = os . path . dirname ( filename ) , delete = False , prefix = f"{os.path.basename(filename)}." , * * kw , ) as tf : if self . exists ( filename ) : os . chmod ( tf . name , os . stat ( filename ) . st_mode & 0o7777 ) tf . has_changed = False # type: ignore yield tf if not self . exists ( tf . name ) : return filename_tmp = tf . name if self . exists ( filename ) and self . compare_files ( filename , filename_tmp ) : logger . debug ( f"File not changed...deleting temporary file: {filename_tmp}" ) os . unlink ( filename_tmp ) else : logger . debug ( f"Modifying destination: {filename!s} with: {filename_tmp}" ) self . move_file ( filename_tmp , filename )