summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--metadata/metabuilder.c6
-rw-r--r--metadata/metabuilder.h2
-rw-r--r--metadata/metatree.c16
3 files changed, 18 insertions, 6 deletions
diff --git a/metadata/metabuilder.c b/metadata/metabuilder.c
index 58bb57bd..c7e69fac 100644
--- a/metadata/metabuilder.c
+++ b/metadata/metabuilder.c
@@ -843,8 +843,8 @@ get_journal_filename (const char *filename, guint32 random_tag)
return g_strconcat (filename, "-", tag, ".log", NULL);
}
-static gboolean
-create_new_journal (const char *filename, guint32 random_tag)
+gboolean
+meta_builder_create_new_journal (const char *filename, guint32 random_tag)
{
char *journal_name;
guint32 size_offset;
@@ -1016,7 +1016,7 @@ meta_builder_write (MetaBuilder *builder,
if (!write_all_data_and_close (fd, out->str, out->len))
goto out;
- if (!create_new_journal (filename, random_tag))
+ if (!meta_builder_create_new_journal (filename, random_tag))
goto out;
/* Open old file so we can set it rotated */
diff --git a/metadata/metabuilder.h b/metadata/metabuilder.h
index 364c0d84..ad3876ff 100644
--- a/metadata/metabuilder.h
+++ b/metadata/metabuilder.h
@@ -68,6 +68,8 @@ void meta_builder_copy (MetaBuilder *builder,
guint64 mtime);
gboolean meta_builder_write (MetaBuilder *builder,
const char *filename);
+gboolean meta_builder_create_new_journal (const char *filename,
+ guint32 random_tag);
MetaFile * metafile_new (const char *name,
MetaFile *parent);
void metafile_free (MetaFile *file);
diff --git a/metadata/metatree.c b/metadata/metatree.c
index 20b78627..8e2ab46c 100644
--- a/metadata/metatree.c
+++ b/metadata/metatree.c
@@ -1146,20 +1146,30 @@ meta_journal_open (MetaTree *tree, const char *filename, gboolean for_write, gui
char *data;
char *journal_filename;
int open_flags, mmap_prot;
+ gboolean retried;
g_assert (sizeof (MetaJournalHeader) == 20);
-
- journal_filename = get_journal_filename (filename, tag);
+ retried = FALSE;
if (for_write)
open_flags = O_RDWR;
else
open_flags = O_RDONLY;
+ retry:
+ journal_filename = get_journal_filename (filename, tag);
fd = safe_open (tree, journal_filename, open_flags);
g_free (journal_filename);
if (fd == -1)
- return NULL;
+ {
+ if (errno == ENOENT && tree->for_write && !retried)
+ {
+ retried = TRUE;
+ if (meta_builder_create_new_journal (filename, tag))
+ goto retry;
+ }
+ return NULL;
+ }
if (fstat (fd, &statbuf) != 0 ||
statbuf.st_size < sizeof (MetaJournalHeader))