From 39500418018e4f0f4665b06482dad4668e3349ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 5 Jul 2026 12:34:38 +0200 Subject: [PATCH] core: fix time-of-check/time-of-use race condition on theme files Open theme files directly instead of probing them with access() first in commands /theme apply, /theme rename and /theme info. The renamed file is now created with O_CREAT | O_EXCL so an existing theme is never clobbered. --- po/cs.po | 9 +--- po/de.po | 9 +--- po/es.po | 9 +--- po/fr.po | 56 +---------------------- po/hu.po | 8 +--- po/it.po | 9 +--- po/ja.po | 9 +--- po/pl.po | 9 +--- po/pt.po | 9 +--- po/pt_BR.po | 9 +--- po/ru.po | 8 +--- po/sr.po | 9 +--- po/tr.po | 9 +--- po/weechat.pot | 6 +-- src/core/core-command.c | 4 +- src/core/core-theme.c | 71 ++++++++++++++++------------- tests/unit/core/test-core-theme.cpp | 13 +++++- 17 files changed, 79 insertions(+), 177 deletions(-) diff --git a/po/cs.po b/po/cs.po index 6c7ed4f9a..5fc73a36d 100644 --- a/po/cs.po +++ b/po/cs.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-05-30 14:01+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:29+0200\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: Czech \n" "Language: cs\n" @@ -6364,11 +6364,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%sUpozornění: %s, řádek %d: neznámý identifikátor sekce (\"%s\")" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: nemůžu parsovat soubor \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/de.po b/po/de.po index 7e260728a..2f60562d6 100644 --- a/po/de.po +++ b/po/de.po @@ -26,8 +26,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:28+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:29+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" "Language: de\n" @@ -7206,11 +7206,6 @@ msgstr "" "%sWarnung: %s, Zeile %d: ignoriert unbekannte Einstellung für Sektion " "\"%s\": %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: Datei \"%s\" Analyse nicht möglich" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/es.po b/po/es.po index 8187c6120..e6e25168e 100644 --- a/po/es.po +++ b/po/es.po @@ -24,8 +24,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:46+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:29+0200\n" "Last-Translator: Santiago Forero \n" "Language-Team: Spanish \n" "Language: es\n" @@ -6522,11 +6522,6 @@ msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "" "%sAtención: %s, línea %d: opción desconocida para la sección \"%s\": %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: no es posible analizar el archivo \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/fr.po b/po/fr.po index 25cbf873a..54a00fb04 100644 --- a/po/fr.po +++ b/po/fr.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-07-04 22:02+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: French \n" "Language: fr\n" @@ -7087,10 +7087,6 @@ msgstr "%s%s : ligne %d : séparateur '=' manquant" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%s%s : ligne %d : clé [info] \"%s\" inconnue, ignorée" -#, c-format -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%sÉchec de l'analyse du fichier de thème \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " @@ -19043,51 +19039,3 @@ msgid "" msgstr "" "%s%s : impossible d'accepter de continuer le fichier \"%s\" (port : %d, " "position de départ : %llu) : xfer non trouvé ou non prêt pour le transfert" - -#~ msgid "Automatic backup written before /theme apply" -#~ msgstr "Sauvegarde automatique écrite avant /theme apply" - -#~ msgid "" -#~ "Welcome to WeeChat!\n" -#~ "\n" -#~ "If you are discovering WeeChat, it is recommended to read at least the " -#~ "quickstart guide, and the user's guide if you have some time; they " -#~ "explain main WeeChat concepts.\n" -#~ "All WeeChat docs are available at: https://weechat.org/doc/\n" -#~ "\n" -#~ "Moreover, there is inline help with /help on all commands and options " -#~ "(use Tab key to complete the name).\n" -#~ "The command /fset can help to customize WeeChat.\n" -#~ "\n" -#~ "You can add and connect to an IRC server with /server and /connect " -#~ "commands (see /help server)." -#~ msgstr "" -#~ "Bienvenue dans WeeChat !\n" -#~ "\n" -#~ "Si vous découvrez WeeChat, il est recommandé de lire au moins le guide de " -#~ "démarrage rapide, et le guide utilisateur si vous avez le temps ; ils " -#~ "expliquent les concepts principaux de WeeChat.\n" -#~ "Toutes les documentations WeeChat sont disponibles ici : https://" -#~ "weechat.org/doc/\n" -#~ "\n" -#~ "De plus, il y a de l'aide en ligne avec /help sur toutes les commandes et " -#~ "options (utilisez la touche Tab pour compléter le nom).\n" -#~ "La commande /fset peut aider à paramétrer WeeChat.\n" -#~ "\n" -#~ "Vous pouvez ajouter et vous connecter à un serveur IRC avec les " -#~ "commandes /server et /connect (voir /help server)." - -#~ msgid "" -#~ "raw[delete]: delete a user theme file (refuses to delete built-in themes, " -#~ "which have no file)" -#~ msgstr "raw[delete] : supprimer un fichier thème de l'utilisateur" - -#~ msgid "No theme registered" -#~ msgstr "Aucun thème enregistré" - -#~ msgid "" -#~ "raw[list]: list registered themes (default action with no argument); " -#~ "active theme is marked with \"->\"" -#~ msgstr "" -#~ "raw[list] : afficher les thèmes enregistrés (sans paramètre, cette liste " -#~ "est affichée), le thème actif est marqué avec \"->\"" diff --git a/po/hu.po b/po/hu.po index 3613a7605..3cf147f36 100644 --- a/po/hu.po +++ b/po/hu.po @@ -22,8 +22,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-03-08 08:59+0100\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: Hungarian \n" "Language: hu\n" @@ -6030,10 +6030,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%s %s, %d. sor: ismeretlen csoportazonosító (\"%s\")\n" -#, fuzzy, c-format -msgid "%sFailed to parse theme file \"%s\"" -msgstr "Nem sikerült a(z) \"%s\" naplófájlt írni\n" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/it.po b/po/it.po index aaab9288b..66c3b63af 100644 --- a/po/it.po +++ b/po/it.po @@ -22,8 +22,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-05-30 14:02+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: Italian \n" "Language: it\n" @@ -6510,11 +6510,6 @@ msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "" "%sAttenzione: %s, riga %d: opzione sconosciuta per la sezione \"%s\": %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: impossibile analizzare il file \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/ja.po b/po/ja.po index a0f372408..f0bc11dc3 100644 --- a/po/ja.po +++ b/po/ja.po @@ -22,8 +22,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-05-30 14:02+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" "Language: ja\n" @@ -6686,11 +6686,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%s警告: %s、行 %d: セクション \"%s\" の無効なオプション: %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: ファイル \"%s\" を解析できません" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/pl.po b/po/pl.po index 96efe7528..a5bef68c6 100644 --- a/po/pl.po +++ b/po/pl.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:55+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Krzysztof Korościk \n" "Language-Team: Polish \n" "Language: pl\n" @@ -6867,11 +6867,6 @@ msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "" "%sOstrzeżenie: %s, linia %d: ignoruje nieznaną opcję dla sekcji \"%s\": %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: nie można przetworzyć pliku \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/pt.po b/po/pt.po index 61d7a10db..58eacc2e5 100644 --- a/po/pt.po +++ b/po/pt.po @@ -22,8 +22,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:48+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese \n" "Language: pt\n" @@ -6742,11 +6742,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%sAviso: %s, linha %d: opção desconhecida na secção \"%s\": %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: não foi possível analisar o ficheiro \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/pt_BR.po b/po/pt_BR.po index afc97743e..a02ad824e 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -46,8 +46,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:49+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Érico Nogueira \n" "Language-Team: Portuguese (Brazil) \n" "Language: pt_BR\n" @@ -6408,11 +6408,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%sAviso: %s, linha %d: opção \"%s\" desconhecido para seção \"%s\"" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: não foi possível interpretar arquivo \"%s\"" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/ru.po b/po/ru.po index 94bf58b6d..c832f66c4 100644 --- a/po/ru.po +++ b/po/ru.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-03-08 08:59+0100\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:28+0200\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: Russian \n" "Language: ru\n" @@ -6067,10 +6067,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%s %s, строка %d: неизвестный идентификатор секции (\"%s\")\n" -#, fuzzy, c-format -msgid "%sFailed to parse theme file \"%s\"" -msgstr "Не могу записать лог-файл \"%s\"\n" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/sr.po b/po/sr.po index 7a4fc9e07..366c06eca 100644 --- a/po/sr.po +++ b/po/sr.po @@ -22,8 +22,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:52+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:29+0200\n" "Last-Translator: Ivan Pešić \n" "Language-Team: Serbian \n" "Language: sr\n" @@ -6849,11 +6849,6 @@ msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "" "%sУпозорење: %s, линија %d: игнорише се непозната опција за одељак „%s”: %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: није успело парсирање фајла „%s”" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/tr.po b/po/tr.po index 39f887706..7873b2576 100644 --- a/po/tr.po +++ b/po/tr.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" -"PO-Revision-Date: 2026-06-28 08:53+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" +"PO-Revision-Date: 2026-07-05 12:29+0200\n" "Last-Translator: Emir SARI \n" "Language-Team: Turkish \n" "Language: tr\n" @@ -6646,11 +6646,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "%sUyarı: %s, %d. satır: \"%s\" bölümü için bilinmeyen seçenek: %s" -#, fuzzy, c-format -#| msgid "%s%s: unable to parse file \"%s\"" -msgid "%sFailed to parse theme file \"%s\"" -msgstr "%s%s: \"%s\" dosyası ayrıştırılamıyor" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/po/weechat.pot b/po/weechat.pot index 21358ae17..44c736c61 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 22:01+0200\n" +"POT-Creation-Date: 2026-07-05 12:20+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -5624,10 +5624,6 @@ msgstr "" msgid "%s%s: line %d: ignoring unknown [info] key \"%s\"" msgstr "" -#, c-format -msgid "%sFailed to parse theme file \"%s\"" -msgstr "" - #, c-format msgid "" "%sUnable to create theme backup; aborting apply (disable option " diff --git a/src/core/core-command.c b/src/core/core-command.c index b66c53c5f..9372215cb 100644 --- a/src/core/core-command.c +++ b/src/core/core-command.c @@ -7369,9 +7369,7 @@ COMMAND_CALLBACK(theme) COMMAND_MIN_ARGS(3, "info"); /* file shadows registry: try user file first */ path = theme_user_file_path (argv[2]); - file_theme = NULL; - if (path && (access (path, R_OK) == 0)) - file_theme = theme_file_parse (path); + file_theme = (path) ? theme_file_parse (path) : NULL; if (!file_theme) { free (path); diff --git a/src/core/core-theme.c b/src/core/core-theme.c index a3b47f156..6733d9dc9 100644 --- a/src/core/core-theme.c +++ b/src/core/core-theme.c @@ -25,6 +25,8 @@ #include "config.h" #endif +#include +#include #include #include #include @@ -945,18 +947,11 @@ theme_apply (const char *name) * so user themes have no steady-state memory footprint. */ path = theme_user_file_path (name); - if (path && (access (path, R_OK) == 0)) - { + if (path) file_theme = theme_file_parse (path); - if (!file_theme) - { - gui_chat_printf (NULL, - _("%sFailed to parse theme file \"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - path); - free (path); - return WEECHAT_RC_ERROR; - } + free (path); + if (file_theme) + { theme = file_theme; } else @@ -968,11 +963,9 @@ theme_apply (const char *name) _("%sTheme \"%s\" not found"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], name); - free (path); return WEECHAT_RC_ERROR; } } - free (path); /* create a backup of current themable state, if enabled */ if (CONFIG_BOOLEAN(config_look_theme_backup) @@ -1187,7 +1180,7 @@ theme_rename (const char *old_name, const char *new_name) char *old_path, *new_path, line[2048]; FILE *fin, *fout; const char *trimmed; - int in_info, name_done; + int in_info, name_done, fd; if (!old_name || !old_name[0] || !new_name || !new_name[0]) return WEECHAT_RC_ERROR; @@ -1230,39 +1223,53 @@ theme_rename (const char *old_name, const char *new_name) old_path = theme_user_file_path (old_name); if (!old_path) return WEECHAT_RC_ERROR; - if (access (old_path, R_OK) != 0) - { - gui_chat_printf (NULL, - _("%sTheme \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - old_name); - free (old_path); - return WEECHAT_RC_ERROR; - } - new_path = theme_user_file_path (new_name); if (!new_path) { free (old_path); return WEECHAT_RC_ERROR; } - if (access (new_path, F_OK) == 0) + + fin = fopen (old_path, "r"); + if (!fin) { gui_chat_printf (NULL, - _("%sTheme \"%s\" already exists"), + _("%sTheme \"%s\" not found"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - new_name); + old_name); free (old_path); free (new_path); return WEECHAT_RC_ERROR; } - fin = fopen (old_path, "r"); - fout = (fin) ? fopen (new_path, "w") : NULL; - if (!fin || !fout) + fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL, 0666); + if (fd < 0) { - if (fin) - fclose (fin); + if (errno == EEXIST) + { + gui_chat_printf (NULL, + _("%sTheme \"%s\" already exists"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + new_name); + } + else + { + gui_chat_printf (NULL, + _("%sFailed to rename theme \"%s\" to \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + old_name, new_name); + } + fclose (fin); + free (old_path); + free (new_path); + return WEECHAT_RC_ERROR; + } + fout = fdopen (fd, "w"); + if (!fout) + { + close (fd); + unlink (new_path); + fclose (fin); gui_chat_printf (NULL, _("%sFailed to rename theme \"%s\" to \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], diff --git a/tests/unit/core/test-core-theme.cpp b/tests/unit/core/test-core-theme.cpp index 15d1a6029..b7fff3865 100644 --- a/tests/unit/core/test-core-theme.cpp +++ b/tests/unit/core/test-core-theme.cpp @@ -942,7 +942,7 @@ TEST(CoreTheme, Delete) TEST(CoreTheme, Rename) { - char *src_path, *dst_path; + char *src_path = NULL, *dst_path = NULL; struct stat st; FILE *file; char buf[2048]; @@ -974,6 +974,17 @@ TEST(CoreTheme, Rename) /* refuses target that already exists */ LONGS_EQUAL(WEECHAT_RC_OK, theme_save ("rn_dst")); LONGS_EQUAL(WEECHAT_RC_ERROR, theme_rename ("rn_src", "rn_dst")); + /* the refused rename must not have clobbered the existing target */ + dst_path = theme_user_file_path ("rn_dst"); + CHECK(dst_path != NULL); + file = fopen (dst_path, "r"); + CHECK(file != NULL); + len = fread (buf, 1, sizeof (buf) - 1, file); + buf[len] = '\0'; + fclose (file); + CHECK(strstr (buf, "name = \"rn_dst\"") != NULL); + free (dst_path); + dst_path = NULL; LONGS_EQUAL(WEECHAT_RC_OK, theme_delete ("rn_dst")); /* happy path: rename moves the file and rewrites the [info] name */