~mandel/ubuntuone-client/donot-add-watches-parents

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-metadata.c

  • Committer: Rodrigo Moya
  • Date: 2010-09-16 16:13:19 UTC
  • mto: This revision was merged to the branch mainline in revision 708.
  • Revision ID: rodrigo.moya@canonical.com-20100916161319-iszkk4nutpiptg7x
Use hashes only for files, and 'quick_tree_synced' for directories

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        gchar *share_id;
31
31
        gchar *node_id;
32
32
        gboolean is_synced;
 
33
        gboolean is_dir;
33
34
};
34
35
 
35
36
static void
97
98
                syncdaemon_metadata_set_server_hash (metadata, g_hash_table_lookup (hash, "server_hash"));
98
99
                syncdaemon_metadata_set_share_id (metadata, g_hash_table_lookup (hash, "share_id"));
99
100
                syncdaemon_metadata_set_node_id (metadata, g_hash_table_lookup (hash, "node_id"));
100
 
                syncdaemon_metadata_set_is_synced (metadata, g_hash_table_lookup (hash, "quick_tree_synced"));
 
101
                syncdaemon_metadata_set_is_synced (
 
102
                        metadata,
 
103
                        g_strcmp0 (g_hash_table_lookup (hash, "quick_tree_synced"), "synced") == 0);
 
104
                metadata->priv->is_dir = g_strcmp0 (g_hash_table_lookup (hash, "is_dir"), "True") == 0;
101
105
                /* FIXME: we ignore the other values in the hash table since none of our
102
106
                   clients use them for now */
103
107
        }
236
240
gboolean
237
241
syncdaemon_metadata_get_is_synced (SyncdaemonMetadata *metadata)
238
242
{
239
 
        const gchar * local, * server;
240
 
        gboolean is_updated;
 
243
        gchar *local, *server;
 
244
        gboolean is_updated;
241
245
 
242
246
        g_return_val_if_fail (SYNCDAEMON_IS_METADATA (metadata), FALSE);
243
247
 
244
 
        local = syncdaemon_metadata_get_local_hash (metadata);
245
 
        server = syncdaemon_metadata_get_server_hash (metadata);
246
 
 
247
 
        is_updated = local && server && *local && *server &&
248
 
                strcmp (local, server) == 0;
249
 
 
250
 
        /* we are synced if both is_synced and is_updated are true */
251
 
        return metadata->priv->is_synced && is_updated;
 
248
        /* If it's a dir, we have the 'quick_tree_synced' value */
 
249
        if (metadata->priv->is_dir)
 
250
                return metadata->priv->is_synced;
 
251
 
 
252
        local = metadata->priv->local_hash;
 
253
        server = metadata->priv->server_hash;
 
254
 
 
255
        is_updated = local && server && *local && *server &&
 
256
                g_strcmp0 (local, server) == 0;
 
257
 
 
258
        return is_updated;
252
259
}
253
260
 
254
261
/**
255
262
 * syncdaemon_metadata_set_is_synced:
256
263
 */
257
264
void
258
 
syncdaemon_metadata_set_is_synced (SyncdaemonMetadata *metadata, const gchar *is_synced)
 
265
syncdaemon_metadata_set_is_synced (SyncdaemonMetadata *metadata, gboolean is_synced)
259
266
{
260
267
        g_return_if_fail (SYNCDAEMON_IS_METADATA (metadata));
261
268
 
262
 
        metadata->priv->is_synced = !is_synced || (is_synced && *is_synced);
 
269
        metadata->priv->is_synced = is_synced;
263
270
}
264
271