Re: How gvdb_table_is_valid works on glib/dconf



hi Joshua

On 11-02-16 04:09 AM, Joshua Lee wrote:
I can not understand while gvdb_table_is_valid can check the on-disk
gvdb table is valid.

The very first thing that comes in any GVDB file is the string "GVariant". That's normally why *data should be non-zero, so !!*data will be 1.

When dconf system databases are replaced, the old file has its header overwritten with zeros to indicate that applications need to reopen it on their next access. This cases *data to be 0, so !!*data is also zero.

See this code in dconf-update, for example:


        var fd = Posix.open (filename, Posix.O_WRONLY);

        if (fd < 0 && errno != Posix.ENOENT) {
            var saved_error = errno;
throw new FileError.FAILED ("Can not open '%s' for replacement: %s", filename, strerror (saved_error));
        }

        try {
            table.write_contents (filename);

            if (fd >= 0) {
                Posix.write (fd, "\0\0\0\0\0\0\0\0", 8);
            }
        } finally {
            if (fd >= 0) {
                Posix.close (fd);
            }
        }


Basically, it opens the old file and holds on to the fd while replacing it with the new file. It then zeros-out the header of the old file to indicate that users should reopen (thus getting the new file).

Hope that helps.

Cheers


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]