1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Merge pull request #922 from dequis/fix-new-config-file-write

Fix /save not working if the config didn't previously exist
This commit is contained in:
ailin-nemui 2018-09-04 09:35:21 +02:00 committed by GitHub
commit 8261b2a7c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,6 +302,7 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode)
int ret; int ret;
int fd; int fd;
int save_errno; int save_errno;
const char *base_name;
char *tmp_name = NULL; char *tmp_name = NULL;
char *dest_name = NULL; char *dest_name = NULL;
@ -309,12 +310,20 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode)
g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1); g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1);
g_return_val_if_fail(create_mode != -1 || rec->create_mode != -1, -1); g_return_val_if_fail(create_mode != -1 || rec->create_mode != -1, -1);
base_name = fname != NULL ? fname : rec->fname;
/* expand all symlinks; else we may replace a symlink with a regular file */ /* expand all symlinks; else we may replace a symlink with a regular file */
dest_name = realpath(fname != NULL ? fname : rec->fname, NULL); dest_name = realpath(base_name, NULL);
if (dest_name == NULL) { if (dest_name == NULL) {
config_error(rec, g_strerror(errno)); if (errno == ENOENT) {
ret = -1; dest_name = g_strdup(base_name);
goto out; errno = 0;
} else {
config_error(rec, g_strerror(errno));
ret = -1;
goto out;
}
} }
tmp_name = g_strdup_printf("%s.XXXXXX", dest_name); tmp_name = g_strdup_printf("%s.XXXXXX", dest_name);