diff options
author | Alexander Larsson <alexl@redhat.com> | 2009-06-23 16:27:17 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2009-06-23 16:29:47 +0200 |
commit | 192d3a7db50e42ad40aea8311e1994f53a1efdc0 (patch) | |
tree | 909dcfb954f557e1c7ce5b231c18963c7bdb2a56 /metadata/metatree.c | |
parent | 576f893d4d75900d777f76450ccf5784641908ce (diff) | |
download | gvfs-192d3a7db50e42ad40aea8311e1994f53a1efdc0.tar.gz |
Allow MetaTree open to succeed with no file
You can check with meta_tree_exists if the file actually exists.
This means that lookups work better for the initial set for a non-existing
file.
Diffstat (limited to 'metadata/metatree.c')
-rw-r--r-- | metadata/metatree.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/metadata/metatree.c b/metadata/metatree.c index e6fa62b1..9664fa84 100644 --- a/metadata/metatree.c +++ b/metadata/metatree.c @@ -269,7 +269,7 @@ meta_tree_clear (MetaTree *tree) } tree->len = 0; - if (tree->fd != 0) + if (tree->fd != -1) { close (tree->fd); tree->fd = 0; @@ -447,6 +447,7 @@ meta_tree_init (MetaTree *tree) } meta_builder_free (builder); } + tree->fd = -1; return FALSE; } @@ -526,12 +527,10 @@ meta_tree_open (const char *filename, tree->ref_count = 1; tree->filename = g_strdup (filename); tree->for_write = for_write; + tree->fd = -1; + + meta_tree_init (tree); - if (!meta_tree_init (tree)) - { - meta_tree_unref (tree); - return NULL; - } return tree; } @@ -541,6 +540,12 @@ meta_tree_get_filename (MetaTree *tree) return tree->filename; } +gboolean +meta_tree_exists (MetaTree *tree) +{ + return tree->fd != -1; +} + static GHashTable *cached_trees = NULL; G_LOCK_DEFINE_STATIC (cached_trees); @@ -607,6 +612,9 @@ meta_tree_unref (MetaTree *tree) static gboolean meta_tree_needs_rereading (MetaTree *tree) { + if (tree->fd == -1) + return TRUE; + if (tree->header != NULL && GUINT32_FROM_BE (tree->header->rotated) == 0) return FALSE; /* Got a valid tree and its not rotated */ @@ -734,6 +742,9 @@ meta_tree_lookup (MetaTree *tree, MetaFileDirEnt *dirent; char *path_copy; + if (tree->root == NULL) + return NULL; + path_copy = g_strdup (path); dirent = dir_lookup_path (tree, tree->root, path_copy); g_free (path_copy); |