def flush(self):
        """Write self to .pyftpsync-meta.json."""
        # We DO write meta files even on read-only targets, but not in dry-run mode
        # if self.target.readonly:
        #     write("DirMetadata.flush(%s): read-only; nothing to do" % self.target)
        #     return
        assert self.path == self.target.cur_dir
        if self.target.dry_run:
            # write("DirMetadata.flush(%s): dry-run; nothing to do" % self.target)
            pass

        elif self.was_read and len(self.list) == 0 and len(self.peer_sync) == 0:
            write("Remove empty meta data file: {}".format(self.target))
            self.target.remove_file(self.filename)

        elif not self.modified_list and not self.modified_sync:
            # write("DirMetadata.flush(%s): unmodified; nothing to do" % self.target)
            pass

        else:
            self.dir["_disclaimer"] = "Generated by https://github.com/mar10/pyftpsync"
            self.dir["_time_str"] = pretty_stamp(time.time())
            self.dir["_file_version"] = self.VERSION
            self.dir["_version"] = __version__
            self.dir["_time"] = time.mktime(time.gmtime())

            # We always save utf-8 encoded.
            # `ensure_ascii` would escape all bytes >127 as `\x12` or `\u1234`,
            # which makes it hard to read, so we set it to false.
            # `sort_keys` converts binary keys to unicode using utf-8, so we
            # must make sure that we don't pass cp1225 or other encoded data.
            data = self.dir
            opts = {"indent": 4, "sort_keys": True, "ensure_ascii": False}

            if compat.PY2:
                # The `encoding` arg defaults to utf-8 on Py2 and was removed in Py3
                # opts["encoding"] = "utf-8"
                # Python 2 has problems with mixed keys (str/unicode)
                data = decode_dict_keys(data, "utf-8")

            if not self.PRETTY:
                opts["indent"] = None
                opts["separators"] = (",", ":")

            s = json.dumps(data, **opts)

            self.target.write_text(self.filename, s)
            if self.target.synchronizer:
                self.target.synchronizer._inc_stat("meta_bytes_written", len(s))

        self.modified_list = False
        self.modified_sync = False
Write self to .pyftpsync-meta.json.