diff --git a/builder/builder-utils.c b/builder/builder-utils.c index c156b105..c7295edc 100644 --- a/builder/builder-utils.c +++ b/builder/builder-utils.c @@ -219,3 +219,19 @@ gboolean is_elf_file (const char *path, return FALSE; } + +gboolean directory_is_empty (const char *path) +{ + GDir *dir; + gboolean empty; + + dir = g_dir_open (path, 0, NULL); + if (g_dir_read_name (dir) == NULL) + empty = TRUE; + else + empty = FALSE; + + g_dir_close (dir); + + return empty; +} diff --git a/builder/builder-utils.h b/builder/builder-utils.h index 446d993e..173f3533 100644 --- a/builder/builder-utils.h +++ b/builder/builder-utils.h @@ -37,6 +37,8 @@ gboolean is_elf_file (const char *path, gboolean *is_shared, gboolean *is_stripped); +gboolean directory_is_empty (const char *path); + gboolean xdg_app_matches_path_pattern (const char *path, const char *pattern); void xdg_app_collect_matches_for_path_pattern (const char *path, diff --git a/builder/xdg-app-builder-main.c b/builder/xdg-app-builder-main.c index ad7c7b33..152b1bcd 100644 --- a/builder/xdg-app-builder-main.c +++ b/builder/xdg-app-builder-main.c @@ -30,6 +30,7 @@ #include "libgsystem.h" #include "builder-manifest.h" +#include "builder-utils.h" static gboolean opt_verbose; static gboolean opt_version; @@ -210,9 +211,10 @@ main (int argc, base_dir = g_file_new_for_path (g_get_current_dir ()); app_dir = g_file_new_for_path (app_dir_path); - if (!gs_shutil_rm_rf (app_dir, NULL, &error)) + if (g_file_query_exists (app_dir, NULL) && !directory_is_empty (app_dir_path)) { - g_print ("error removing old app dir '%s': %s\n", app_dir_path, error->message); + g_printerr ("App dir '%s' is not empty. Please delete " + "the existing contents.\n", app_dir_path); return 1; }