1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

use g_mkdir_with_parents() instead of home-baked solution

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2022-03-13 12:02:59 +01:00
parent b8e46552bf
commit 705b6f7806
5 changed files with 15 additions and 45 deletions

View File

@ -3004,7 +3004,7 @@ command_mangen(void)
cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command);
}
mkdir_recursive("docs");
create_dir("docs");
GDateTime* now = g_date_time_new_now_local();
gchar* date = g_date_time_format(now, "%F");

View File

@ -71,43 +71,15 @@ struct curl_data_t
static size_t _data_callback(void* ptr, size_t size, size_t nmemb, void* data);
gboolean
create_dir(char* name)
create_dir(const char* name)
{
struct stat sb;
if (stat(name, &sb) != 0) {
if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
return FALSE;
}
} else {
if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
log_debug("create_dir: %s exists and is not a directory!", name);
return FALSE;
}
if (g_mkdir_with_parents(name, S_IRWXU) != 0) {
log_error("Failed to create directory at '%s' with error '%s'", name, strerror(errno));
return FALSE;
}
return TRUE;
}
gboolean
mkdir_recursive(const char* dir)
{
gboolean result = TRUE;
for (int i = 1; i <= strlen(dir); i++) {
if (dir[i] == '/' || dir[i] == '\0') {
gchar* next_dir = g_strndup(dir, i);
result = create_dir(next_dir);
g_free(next_dir);
if (!result) {
break;
}
}
}
return result;
}
gboolean
copy_file(const char* const sourcepath, const char* const targetpath, const gboolean overwrite_existing)
{

View File

@ -80,8 +80,7 @@ typedef enum {
RESOURCE_XA
} resource_presence_t;
gboolean create_dir(char* name);
gboolean mkdir_recursive(const char* dir);
gboolean create_dir(const char* name);
gboolean copy_file(const char* const src, const char* const target, const gboolean overwrite_existing);
char* str_replace(const char* string, const char* substr, const char* replacement);
gboolean strtoi_range(char* str, int* saveptr, int min, int max, char** err_msg);

View File

@ -67,19 +67,19 @@ files_create_directories(void)
GString* plugins_dir = g_string_new(xdg_data);
g_string_append(plugins_dir, "/profanity/plugins");
if (!mkdir_recursive(themes_dir->str)) {
if (!create_dir(themes_dir->str)) {
log_error("Error while creating directory %s", themes_dir->str);
}
if (!mkdir_recursive(icons_dir->str)) {
if (!create_dir(icons_dir->str)) {
log_error("Error while creating directory %s", icons_dir->str);
}
if (!mkdir_recursive(chatlogs_dir->str)) {
if (!create_dir(chatlogs_dir->str)) {
log_error("Error while creating directory %s", chatlogs_dir->str);
}
if (!mkdir_recursive(logs_dir->str)) {
if (!create_dir(logs_dir->str)) {
log_error("Error while creating directory %s", logs_dir->str);
}
if (!mkdir_recursive(plugins_dir->str)) {
if (!create_dir(plugins_dir->str)) {
log_error("Error while creating directory %s", plugins_dir->str);
}
@ -122,7 +122,7 @@ files_get_log_file(const char* const log_file)
if (log_file) {
gchar* log_path = g_path_get_dirname(log_file);
if (!mkdir_recursive(log_path)) {
if (!create_dir(log_path)) {
log_error("Error while creating directory %s", log_path);
}
g_free(log_path);
@ -198,8 +198,7 @@ files_file_in_account_data_path(const char* const specific_dir, const char* cons
{
gchar* data_path = files_get_account_data_path(specific_dir, jid);
if (g_mkdir_with_parents(data_path, S_IRWXU) != 0) {
log_error("Failed to create directory at '%s' with error '%s'", data_path, strerror(errno));
if (!create_dir(data_path)) {
g_free(data_path);
return NULL;
}

View File

@ -16,7 +16,7 @@ void
create_config_dir(void** state)
{
setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
if (!mkdir_recursive("./tests/files/xdg_config_home/profanity")) {
if (!create_dir("./tests/files/xdg_config_home/profanity")) {
assert_true(FALSE);
}
}
@ -32,7 +32,7 @@ void
create_data_dir(void** state)
{
setenv("XDG_DATA_HOME", "./tests/files/xdg_data_home", 1);
if (!mkdir_recursive("./tests/files/xdg_data_home/profanity")) {
if (!create_dir("./tests/files/xdg_data_home/profanity")) {
assert_true(FALSE);
}
}