def write(self, version):
        """Save new version into self._path in safe way (using temporary file)

        :param version:Version
        """
        with tempfile.NamedTemporaryFile(mode='w', delete=False) as fh:
            fh.write(str(version))

        if self._path.exists():
            shutil.copystat(str(self._path), fh.name)

        try:
            pathlib.Path(fh.name).rename(self._path)
        except OSError as exc:
            # handling situation with tmp file on another device
            if exc.errno == 18 and 'Invalid cross-device link' in exc.strerror:
                with self._path.open(mode='w') as fh:
                    fh.write(str(version))
            else:
                raise