From 1dd3439bb66eae7b61a3ce22b72ae8668fec1b58 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 6 Aug 2020 16:36:59 +0200 Subject: Add lilv_remove() --- src/filesystem.c | 12 ++++++++++++ src/filesystem.h | 4 ++++ src/lilv_internal.h | 2 -- src/state.c | 8 ++------ 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/filesystem.c b/src/filesystem.c index 0d840ec..f521179 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -423,6 +423,18 @@ lilv_file_size(const char* path) return buf.st_size; } +int +lilv_remove(const char* path) +{ +#ifdef _WIN32 + if (lilv_is_directory(path)) { + return !RemoveDirectory(path); + } +#endif + + return remove(path); +} + bool lilv_file_equals(const char* a_path, const char* b_path) { diff --git a/src/filesystem.h b/src/filesystem.h index f5ac35c..14f25d7 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -147,6 +147,10 @@ lilv_create_temporary_directory(const char* pattern); int lilv_create_directories(const char* dir_path); +/// Remove the file or empty directory at `path` +int +lilv_remove(const char* path); + /// Return true iff the given paths point to files with identical contents bool lilv_file_equals(const char* a_path, const char* b_path); diff --git a/src/lilv_internal.h b/src/lilv_internal.h index 212e41a..d603df7 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -39,8 +39,6 @@ extern "C" { # include # define dlopen(path, flags) LoadLibrary(path) # define dlclose(lib) FreeLibrary((HMODULE)lib) -# define unlink(path) _unlink(path) -# define rmdir(path) _rmdir(path) # ifdef _MSC_VER # define __func__ __FUNCTION__ # ifndef snprintf diff --git a/src/state.c b/src/state.c index 3086ea6..474ddbe 100644 --- a/src/state.c +++ b/src/state.c @@ -30,10 +30,6 @@ #include "lv2/state/state.h" #include "lv2/urid/urid.h" -#ifndef _WIN32 -#include -#endif - #include #include #include @@ -1252,7 +1248,7 @@ static void try_unlink(const char* state_dir, const char* path) { if (!strncmp(state_dir, path, strlen(state_dir))) { - if (lilv_path_exists(path) && unlink(path)) { + if (lilv_path_exists(path) && lilv_remove(path)) { LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); } } @@ -1329,7 +1325,7 @@ lilv_state_delete(LilvWorld* world, } } - if (rmdir(state->dir)) { + if (lilv_remove(state->dir)) { LILV_ERRORF("Failed to remove directory %s (%s)\n", state->dir, strerror(errno)); } -- cgit v1.2.1