From e54de0e06b678bb6444ce3ae9aaacba2c09cc9d8 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Fri, 31 Mar 2023 16:06:00 -0400 Subject: [PATCH] rg_storage: Removed spurious logging --- components/retro-go/rg_gui.c | 4 +- components/retro-go/rg_storage.c | 75 ++++++++++++-------------------- 2 files changed, 30 insertions(+), 49 deletions(-) diff --git a/components/retro-go/rg_gui.c b/components/retro-go/rg_gui.c index ab2e4029..ef2e748e 100644 --- a/components/retro-go/rg_gui.c +++ b/components/retro-go/rg_gui.c @@ -508,7 +508,7 @@ void rg_gui_draw_status_bars(void) (int)round(stats.totalFPS), (int)round(stats.busyPercent)); - if (app->romPath && strlen(app->romPath) > max_len) + if (app->romPath && strlen(app->romPath) > max_len - 1) snprintf(footer, max_len, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 4))); else if (app->romPath) snprintf(footer, max_len, "%s", app->romPath); @@ -720,7 +720,7 @@ int rg_gui_dialog(const char *title, const rg_gui_option_t *options_const, int s if (option->update_cb) option->update_cb(option, RG_DIALOG_INIT); } - RG_LOGI("text_buffer usage = %d\n", (intptr_t)(text_buffer_ptr - text_buffer)); + RG_LOGD("text_buffer usage = %d\n", (intptr_t)(text_buffer_ptr - text_buffer)); rg_gui_draw_status_bars(); rg_gui_draw_dialog(title, options, sel); diff --git a/components/retro-go/rg_storage.c b/components/retro-go/rg_storage.c index e9e87234..425d84c9 100644 --- a/components/retro-go/rg_storage.c +++ b/components/retro-go/rg_storage.c @@ -202,64 +202,49 @@ bool rg_storage_mkdir(const char *dir) { RG_ASSERT(dir, "Bad param"); - char temp[RG_PATH_MAX + 1]; - int ret = mkdir(dir, 0777); + if (mkdir(dir, 0777) == 0) + return true; - if (ret == -1) + // FIXME: Might want to stat to see if it's a dir + if (errno == EEXIST) + return true; + + // Possibly missing some parents, try creating them + char *temp = strdup(dir); + for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++) { - if (errno == EEXIST) - return true; - - strncpy(temp, dir, RG_PATH_MAX); - - for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++) + if (*p == '/') { - if (*p == '/') + *p = 0; + if (strlen(temp) > 0) { - *p = 0; - if (strlen(temp) > 0) - { - RG_LOGI("Creating %s\n", temp); - mkdir(temp, 0777); - } - *p = '/'; - while (*(p + 1) == '/') - p++; + mkdir(temp, 0777); } + *p = '/'; + while (*(p + 1) == '/') + p++; } - - ret = mkdir(temp, 0777); } + free(temp); - if (ret == 0) - { - RG_LOGI("Folder created %s\n", dir); - } + // Finally try again + if (mkdir(dir, 0777) == 0) + return true; - return (ret == 0); + return false; } bool rg_storage_delete(const char *path) { RG_ASSERT(path, "Bad param"); - DIR *dir; - if (unlink(path) == 0) - { - RG_LOGI("Deleted file %s\n", path); + // errno has proven to be somewhat unreliable across our targets + // let's use a bruteforce approach... + if (unlink(path) == 0 || rmdir(path) == 0) return true; - } - else if (errno == ENOENT) - { - // The path already doesn't exist! - return true; - } - else if (rmdir(path) == 0) - { - RG_LOGI("Deleted empty folder %s\n", path); - return true; - } - else if ((dir = opendir(path))) + + DIR *dir = opendir(path); + if (dir) { char pathbuf[128]; // Smaller than RG_PATH_MAX to prevent issues due to lazy recursion... struct dirent *ent; @@ -272,11 +257,7 @@ bool rg_storage_delete(const char *path) rg_storage_delete(pathbuf); } closedir(dir); - if (rmdir(path) == 0) - { - RG_LOGI("Deleted folder %s\n", path); - return true; - } + return rmdir(path) == 0; } return false;