From 80b069cfa99275331c28a15f8c7b9c77c41d80c4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 2 Oct 2007 14:04:46 +0200 Subject: [PATCH] fsck.c: Fix several bugs in dump mode. - Don't abort if a directory can't be created because it already exists. - Use correct variable for the disk storage name column. - If more than one table is to be dumped, use a directory for each table. - Remove __a_unused for main()'s argc which _is_ being used. --- fsck.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fsck.c b/fsck.c index 391516f3..4d719820 100644 --- a/fsck.c +++ b/fsck.c @@ -751,7 +751,7 @@ static int dump_row(struct osl_table *t, unsigned row_num, const char *row_dir) if (!t->num_disk_storage_columns) return 1; dsnc = t->disk_storage_name_column; - ret = get_mapped_object(t, dsnc, i, &obj); + ret = get_mapped_object(t, dsnc, row_num, &obj); if (ret < 0) return ret; hash_object(&obj, hash); @@ -789,12 +789,12 @@ static int dump_rows(char *dump_dir, struct osl_table *t) current_dir = make_message("%s/rows_%u-%u", dump_dir, i, i + 999); PARA_NOTICE_LOG("dumping rows %u - %u\n", i, i + 999); ret = para_mkdir(current_dir, 0777); - if (ret < 0) + if (ret < 0 && ret != -E_EXIST) goto out; } row_dir = make_message("%s/row_%03u", current_dir, i); ret = para_mkdir(row_dir, 0777); - if (ret < 0) { + if (ret < 0 && ret != -E_EXIST) { free(row_dir); goto out; } @@ -813,13 +813,18 @@ static int dump_table(char *dump_dir, struct osl_table_description *desc) struct osl_table *t = NULL; int fd, ret = fsck_init(desc, &t); char *desc_file; + char *table_dump_dir = NULL; if (ret < 0) goto out; ret = para_mkdir(dump_dir, 0777); - if (ret < 0) + if (ret < 0 && ret != -E_EXIST) + goto out; + table_dump_dir = make_message("%s/%s", dump_dir, desc->name); + ret = para_mkdir(table_dump_dir, 0777); + if (ret < 0 && ret != -E_EXIST) goto out; - desc_file = make_message("%s/table_description.c", dump_dir); + desc_file = make_message("%s/table_description.c", table_dump_dir); ret = para_open(desc_file, O_WRONLY | O_CREAT | O_EXCL, 0644); free(desc_file); if (ret < 0) @@ -829,8 +834,9 @@ static int dump_table(char *dump_dir, struct osl_table_description *desc) close(fd); if (ret < 0) goto out; - ret = dump_rows(dump_dir, t); + ret = dump_rows(table_dump_dir, t); out: + free(table_dump_dir); fsck_cleanup(t); return ret; } @@ -921,7 +927,7 @@ static int check_all_tables(char *base_dir) return ret; } -int main(__a_unused int argc, char **argv) +int main(int argc, char **argv) { int i, ret; char *base_dir = NULL; -- 2.39.5