Skip to content

Commit

Permalink
reduce cleanup code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Dec 5, 2023
1 parent ad77e33 commit e6953bf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
37 changes: 20 additions & 17 deletions src/gufi_dir2index.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,18 @@ int main(int argc, char *argv[]) {
}
}

int rc = 0;

if (setup_dst(pa.in.nameto.data) != 0) {
trie_free(pa.skip);
return -1;
rc = -1;
goto free_skip;
}

init_template_db(&pa.db);
if (create_dbdb_template(&pa.db) != 0) {
fprintf(stderr, "Could not create template file\n");
trie_free(pa.skip);
return -1;
rc = -1;
goto free_skip;
}

/*
Expand All @@ -394,16 +396,15 @@ int main(int argc, char *argv[]) {
* so that when querying "${dst}", no error is printed
*/
if (create_empty_dbdb(&pa.db, &pa.in.nameto, geteuid(), getegid()) != 0) {
trie_free(pa.skip);
return -1;
rc = -1;
goto free_skip;
}

init_template_db(&pa.xattr);
if (create_xattrs_template(&pa.xattr) != 0) {
fprintf(stderr, "Could not create xattr template file\n");
close_template_db(&pa.db);
trie_free(pa.skip);
return -1;
rc = -1;
goto free_db;
}

const uint64_t queue_depth = pa.in.target_memory_footprint / sizeof(struct work) / pa.in.maxthreads;
Expand All @@ -415,10 +416,8 @@ int main(int argc, char *argv[]) {
if (QPTPool_start(pool) != 0) {
fprintf(stderr, "Error: Failed to start thread pool\n");
QPTPool_destroy(pool);
close_template_db(&pa.xattr);
close_template_db(&pa.db);
trie_free(pa.skip);
return -1;
rc = -1;
goto free_xattr;
}

fprintf(stdout, "Creating GUFI Index %s with %zu threads\n", pa.in.nameto.data, pa.in.maxthreads);
Expand Down Expand Up @@ -472,9 +471,6 @@ int main(int argc, char *argv[]) {
free(roots[i]);
}
free(roots);
close_template_db(&pa.xattr);
close_template_db(&pa.db);
trie_free(pa.skip);

uint64_t total_files = 0;
for(size_t i = 0; i < pa.in.maxthreads; i++) {
Expand All @@ -489,5 +485,12 @@ int main(int argc, char *argv[]) {
fprintf(stdout, "Dirs/Sec: %.2Lf\n", thread_count / processtime);
fprintf(stdout, "Files/Sec: %.2Lf\n", total_files / processtime);

return 0;
free_xattr:
close_template_db(&pa.xattr);
free_db:
close_template_db(&pa.db);
free_skip:
trie_free(pa.skip);

return rc;
}
38 changes: 20 additions & 18 deletions src/gufi_trace2index.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,13 @@ int main(int argc, char *argv[]) {
return -1;
}

int rc = 0;

init_template_db(&pa.db);
if (create_dbdb_template(&pa.db) != 0) {
fprintf(stderr, "Could not create template file\n");
close_traces(traces, trace_count);
return -1;
rc = -1;
goto free_traces;
}

struct stat st;
Expand All @@ -681,8 +683,8 @@ int main(int argc, char *argv[]) {

if (dupdir(pa.in.nameto.data, &st)) {
fprintf(stderr, "Could not create directory %s\n", pa.in.nameto.data);
close_traces(traces, trace_count);
return -1;
rc = -1;
goto free_traces;
}

/*
Expand All @@ -691,16 +693,15 @@ int main(int argc, char *argv[]) {
* so that when querying "${dst}", no error is printed
*/
if (create_empty_dbdb(&pa.db, &pa.in.nameto, geteuid(), getegid()) != 0) {
close_traces(traces, trace_count);
return -1;
rc = -1;
goto free_traces;
}

init_template_db(&pa.xattr);
if (create_xattrs_template(&pa.xattr) != 0) {
fprintf(stderr, "Could not create xattr template file\n");
close_template_db(&pa.db);
close_traces(traces, trace_count);
return -1;
rc = -1;
goto free_db;
}

#if defined(DEBUG) && defined(PER_THREAD_STATS)
Expand All @@ -716,10 +717,8 @@ int main(int argc, char *argv[]) {
if (QPTPool_start(pool) != 0) {
fprintf(stderr, "Error: Failed to start thread pool\n");
QPTPool_destroy(pool);
close_template_db(&pa.xattr);
close_template_db(&pa.db);
close_traces(traces, trace_count);
return -1;
rc = -1;
goto free_xattr;
}

fprintf(stdout, "Creating GUFI Index %s with %zu threads\n", pa.in.nameto.data, pa.in.maxthreads);
Expand Down Expand Up @@ -753,10 +752,6 @@ int main(int argc, char *argv[]) {
/* don't count as part of processtime */
QPTPool_destroy(pool);

close_template_db(&pa.xattr);
close_template_db(&pa.db);
close_traces(traces, trace_count);

#if defined(DEBUG) && defined(PER_THREAD_STATS)
OutputBuffers_flush_to_single(&debug_output_buffers, stderr);
OutputBuffers_destroy(&debug_output_buffers);
Expand Down Expand Up @@ -795,5 +790,12 @@ int main(int argc, char *argv[]) {
fprintf(stdout, "Dirs/Sec: %.2Lf\n", dirs / processtime);
fprintf(stdout, "Files/Sec: %.2Lf\n", files / processtime);

return 0;
free_xattr:
close_template_db(&pa.xattr);
free_db:
close_template_db(&pa.db);
free_traces:
close_traces(traces, trace_count);

return rc;
}

0 comments on commit e6953bf

Please sign in to comment.