diff options
-rw-r--r-- | src/blogc-make/ctx.c | 12 | ||||
-rw-r--r-- | src/blogc-make/exec-native.c | 10 | ||||
-rw-r--r-- | src/blogc-make/exec-native.h | 2 | ||||
-rw-r--r-- | src/blogc-make/rules.c | 2 | ||||
-rwxr-xr-x | tests/blogc-make/check_blogc_make.sh.in | 65 |
5 files changed, 82 insertions, 9 deletions
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index 7b8dfca..454f99a 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -98,12 +98,18 @@ bm_ctx_new(const char *settings_file, bc_error_t **err) char *real_filename = realpath(settings_file, NULL); rv->settings_fctx = bm_filectx_new(rv, real_filename); - rv->root_dir = bc_strdup(dirname(real_filename)); + rv->root_dir = realpath(dirname(real_filename), NULL); free(real_filename); const char *output_dir = bc_trie_lookup(settings->settings, "output_dir"); - rv->output_dir = output_dir[0] == '/' ? bc_strdup(output_dir) : - bc_strdup_printf("%s/%s", rv->root_dir, output_dir); + if (output_dir[0] == '/') { + rv->output_dir = realpath(output_dir, NULL); + } + else { + char *tmp = bc_strdup_printf("%s/%s", rv->root_dir, output_dir); + rv->output_dir = realpath(tmp, NULL); + free(tmp); + } const char *template_dir = bc_trie_lookup(settings->settings, "template_dir"); diff --git a/src/blogc-make/exec-native.c b/src/blogc-make/exec-native.c index 32874b4..8b87d18 100644 --- a/src/blogc-make/exec-native.c +++ b/src/blogc-make/exec-native.c @@ -89,7 +89,7 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose) int -bm_exec_native_rm(bm_filectx_t *dest, bool verbose) +bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose) { if (verbose) printf("Removing file '%s'\n", dest->path); @@ -111,8 +111,7 @@ bm_exec_native_rm(bm_filectx_t *dest, bool verbose) char *dir_short = dirname(short_path); char *dir = dirname(path); - while (0 != strcmp(dir_short, ".")) { - + while ((0 != strcmp(dir_short, ".")) && (0 != strcmp(dir, output_dir))) { DIR *d = opendir(dir); if (d == NULL) { fprintf(stderr, "error: failed to open directory (%s): %s\n", @@ -154,6 +153,11 @@ bm_exec_native_rm(bm_filectx_t *dest, bool verbose) dir = dirname(dir); } + // try to remove output dir + // this is done on a best-effort basis, if we can't remove it, it probably + // have files, so we don't really want to remove it. + rmdir(output_dir); + free(short_path); free(path); diff --git a/src/blogc-make/exec-native.h b/src/blogc-make/exec-native.h index a83b510..f812238 100644 --- a/src/blogc-make/exec-native.h +++ b/src/blogc-make/exec-native.h @@ -13,6 +13,6 @@ #include "ctx.h" int bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose); -int bm_exec_native_rm(bm_filectx_t *dest, bool verbose); +int bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose); #endif /* _MAKE_EXEC_NATIVE_H */ diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index de7d6cc..8a26fb5 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -536,7 +536,7 @@ clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bool verbose) continue; if (fctx->readable) { - rv = bm_exec_native_rm(fctx, verbose); + rv = bm_exec_native_rm(ctx->output_dir, fctx, verbose); if (rv != 0) break; } diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in index b043049..638b149 100755 --- a/tests/blogc-make/check_blogc_make.sh.in +++ b/tests/blogc-make/check_blogc_make.sh.in @@ -795,4 +795,67 @@ Page 2 EOF diff -uN "${TEMP}/proj/_blogc_build/page2.html" "${TEMP}/expected-page2.html" -rm -rf "${TEMP}/proj/_blogc_build" + +### clean rule + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" clean 2>&1 | tee "${TEMP}/output.txt" +grep "_blogc_build/posts\\.html" "${TEMP}/output.txt" +grep "_blogc_build/atoom/index\\.xml" "${TEMP}/output.txt" +grep "_blogc_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt" +grep "_blogc_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt" +grep "_blogc_build/pagination/1\\.html" "${TEMP}/output.txt" +grep "_blogc_build/pagination/2\\.html" "${TEMP}/output.txt" +grep "_blogc_build/pagination/3\\.html" "${TEMP}/output.txt" +grep "_blogc_build/poost/foo\\.html" "${TEMP}/output.txt" +grep "_blogc_build/poost/bar\\.html" "${TEMP}/output.txt" +grep "_blogc_build/poost/baz\\.html" "${TEMP}/output.txt" +grep "_blogc_build/taag/tag1\\.html" "${TEMP}/output.txt" +grep "_blogc_build/taag/tag2\\.html" "${TEMP}/output.txt" +grep "_blogc_build/page1\\.html" "${TEMP}/output.txt" +grep "_blogc_build/page2\\.html" "${TEMP}/output.txt" + +rm "${TEMP}/output.txt" + +[[ ! -d "${TEMP}/proj/_blogc_build" ]] + +export OUTPUT_DIR="${TEMP}/___blogc_build" + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt" +grep "___blogc_build/posts\\.html" "${TEMP}/output.txt" +grep "___blogc_build/atoom/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/pagination/1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/pagination/2\\.html" "${TEMP}/output.txt" +grep "___blogc_build/pagination/3\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/foo\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/bar\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/baz\\.html" "${TEMP}/output.txt" +grep "___blogc_build/taag/tag1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/taag/tag2\\.html" "${TEMP}/output.txt" +grep "___blogc_build/page1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/page2\\.html" "${TEMP}/output.txt" + +rm "${TEMP}/output.txt" + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" clean 2>&1 | tee "${TEMP}/output.txt" +grep "___blogc_build/posts\\.html" "${TEMP}/output.txt" +grep "___blogc_build/atoom/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/atoom/tag1/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/atoom/tag2/index\\.xml" "${TEMP}/output.txt" +grep "___blogc_build/pagination/1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/pagination/2\\.html" "${TEMP}/output.txt" +grep "___blogc_build/pagination/3\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/foo\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/bar\\.html" "${TEMP}/output.txt" +grep "___blogc_build/poost/baz\\.html" "${TEMP}/output.txt" +grep "___blogc_build/taag/tag1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/taag/tag2\\.html" "${TEMP}/output.txt" +grep "___blogc_build/page1\\.html" "${TEMP}/output.txt" +grep "___blogc_build/page2\\.html" "${TEMP}/output.txt" + +rm "${TEMP}/output.txt" + +[[ ! -d "${OUTPUT_DIR}" ]] + +unset OUTPUT_DIR |