From 3c0bdc18f3f99386f57be4cd8e84f99d465a0b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 5 Oct 2019 18:11:39 +0200 Subject: [PATCH] xfer: add option xfer.file.download_temporary_suffix with default value ".part" (closes #1237) --- ChangeLog.adoc | 1 + ReleaseNotes.adoc | 16 +++ doc/de/autogen/user/xfer_options.adoc | 6 + doc/en/autogen/user/xfer_options.adoc | 6 + doc/fr/autogen/user/xfer_options.adoc | 6 + doc/it/autogen/user/xfer_options.adoc | 6 + doc/ja/autogen/user/xfer_options.adoc | 6 + doc/pl/autogen/user/xfer_options.adoc | 6 + po/cs.po | 8 +- po/de.po | 8 +- po/es.po | 8 +- po/fr.po | 13 +- po/hu.po | 8 +- po/it.po | 8 +- po/ja.po | 8 +- po/pl.po | 8 +- po/pt.po | 8 +- po/pt_BR.po | 8 +- po/ru.po | 8 +- po/tr.po | 8 +- po/weechat.pot | 8 +- src/plugins/xfer/xfer-config.c | 9 ++ src/plugins/xfer/xfer-config.h | 1 + src/plugins/xfer/xfer-dcc.c | 2 +- src/plugins/xfer/xfer-file.c | 176 +++++++++++++++++++------- src/plugins/xfer/xfer-network.c | 8 +- src/plugins/xfer/xfer.c | 21 ++- src/plugins/xfer/xfer.h | 3 + 28 files changed, 317 insertions(+), 65 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 55988a11a..7212425df 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -27,6 +27,7 @@ New features:: * irc: add options irc.color.message_kick and irc.color.reason_kick (issue #683, issue #684) * logger: add option logger.file.color_lines (issue #528, issue #621) * script: add options "-ol" and "-il" in command /script to send translated string with list of scripts loaded, display "No scripts loaded" if no scripts are loaded + * xfer: add option xfer.file.download_temporary_suffix with default value ".part" (issue #1237) Bug fixes:: diff --git a/ReleaseNotes.adoc b/ReleaseNotes.adoc index 48cc68380..c4f3a9c2c 100644 --- a/ReleaseNotes.adoc +++ b/ReleaseNotes.adoc @@ -75,6 +75,22 @@ This new server option has three possible values: _irc.network.channel_encode_ to _off_ (so this was the default behavior in previous versions) +[[v2.7_xfer_file_receive_suffix]] +=== Suffix for files received via DCC + +Files received via DCC (xfer plugin) now have a suffix ".part" during the +transfer. When the transfer is successful, the suffix is removed. + +This suffix can be customized with the new option +_xfer.file.download_temporary_suffix_. + +If you prefer the legacy behavior (no suffix added), you can set an empty value +in the new option: + +---- +/set xfer.file.download_temporary_suffix "" +---- + [[v2.6]] == Version 2.6 (2019-09-08) diff --git a/doc/de/autogen/user/xfer_options.adoc b/doc/de/autogen/user/xfer_options.adoc index 2379acd51..4170d7950 100644 --- a/doc/de/autogen/user/xfer_options.adoc +++ b/doc/de/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** Werte: beliebige Zeichenkette ** Standardwert: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** Beschreibung: pass:none[temporary filename suffix used during the transfer for a file received, it is removed after successful transfer; if empty string, no filename suffix is used during the transfer] +** Typ: Zeichenkette +** Werte: beliebige Zeichenkette +** Standardwert: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** Beschreibung: pass:none[Pfad für ausgehende Dateien (falls kein Pfad durch den Anwender angegeben wurde): "%h" wird durch das WeeChat Verzeichnis ersetzt (Standardpfad: "~/.weechat") (Hinweis: Inhalt wird evaluiert, siehe /help eval)] ** Typ: Zeichenkette diff --git a/doc/en/autogen/user/xfer_options.adoc b/doc/en/autogen/user/xfer_options.adoc index d6e502055..e32581273 100644 --- a/doc/en/autogen/user/xfer_options.adoc +++ b/doc/en/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** values: any string ** default value: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** description: pass:none[temporary filename suffix used during the transfer for a file received, it is removed after successful transfer; if empty string, no filename suffix is used during the transfer] +** type: string +** values: any string +** default value: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** description: pass:none[path for reading files when sending (when no path is specified by user): "%h" at beginning of string is replaced by WeeChat home ("~/.weechat" by default) (note: content is evaluated, see /help eval)] ** type: string diff --git a/doc/fr/autogen/user/xfer_options.adoc b/doc/fr/autogen/user/xfer_options.adoc index 89cf9da7d..dd2c0fa95 100644 --- a/doc/fr/autogen/user/xfer_options.adoc +++ b/doc/fr/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** valeurs: toute chaîne ** valeur par défaut: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** description: pass:none[suffixe de fichier temporaire utilisé pendant le transfert pour un fichier reçu, il est supprimé après un transfert réussi ; si chaîne vide, aucun suffixe de fichier n'est utilisé pendant le transfert] +** type: chaîne +** valeurs: toute chaîne +** valeur par défaut: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** description: pass:none[chemin pour lire les fichiers envoyés (quand aucun chemin n'est spécifié par l'utilisateur) : "%h" au début de la chaîne est remplacé par le répertoire de base WeeChat (par défaut : "~/.weechat") (note : le contenu est évalué, voir /help eval)] ** type: chaîne diff --git a/doc/it/autogen/user/xfer_options.adoc b/doc/it/autogen/user/xfer_options.adoc index e10746396..b7697f343 100644 --- a/doc/it/autogen/user/xfer_options.adoc +++ b/doc/it/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** valori: qualsiasi stringa ** valore predefinito: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** descrizione: pass:none[temporary filename suffix used during the transfer for a file received, it is removed after successful transfer; if empty string, no filename suffix is used during the transfer] +** tipo: stringa +** valori: qualsiasi stringa +** valore predefinito: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** descrizione: pass:none[path for reading files when sending (when no path is specified by user): "%h" at beginning of string is replaced by WeeChat home ("~/.weechat" by default) (note: content is evaluated, see /help eval)] ** tipo: stringa diff --git a/doc/ja/autogen/user/xfer_options.adoc b/doc/ja/autogen/user/xfer_options.adoc index 660f88d4d..d5050dde1 100644 --- a/doc/ja/autogen/user/xfer_options.adoc +++ b/doc/ja/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** 値: 未制約文字列 ** デフォルト値: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** 説明: pass:none[temporary filename suffix used during the transfer for a file received, it is removed after successful transfer; if empty string, no filename suffix is used during the transfer] +** タイプ: 文字列 +** 値: 未制約文字列 +** デフォルト値: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** 説明: pass:none[送信時に読み込むファイルのパス (ユーザがパスを指定しなかった場合に使われます): 文字列最初の "%h" は WeeChat ホームに置換されます (デフォルトでは "~/.weechat" に置換されます) (注意: 内容は評価されます、/help eval 参照)] ** タイプ: 文字列 diff --git a/doc/pl/autogen/user/xfer_options.adoc b/doc/pl/autogen/user/xfer_options.adoc index d028b2a6e..5f88d9071 100644 --- a/doc/pl/autogen/user/xfer_options.adoc +++ b/doc/pl/autogen/user/xfer_options.adoc @@ -104,6 +104,12 @@ ** wartości: dowolny ciąg ** domyślna wartość: `+"%h/xfer"+` +* [[option_xfer.file.download_temporary_suffix]] *xfer.file.download_temporary_suffix* +** opis: pass:none[temporary filename suffix used during the transfer for a file received, it is removed after successful transfer; if empty string, no filename suffix is used during the transfer] +** typ: ciąg +** wartości: dowolny ciąg +** domyślna wartość: `+".part"+` + * [[option_xfer.file.upload_path]] *xfer.file.upload_path* ** opis: pass:none[ścieżka do wysyłanych plików (jeśli nie zostanie ona podana przez użykownika); "%h" na początku ciągu zostanie zastąpione przez katalog domowy WeeChat (domyślnie "~/.weechat") (uwaga: zawartość jest przetwarzana, zobacz /help eval)] ** typ: ciąg diff --git a/po/cs.po b/po/cs.po index a3a88a751..e9dc7799c 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:31+0200\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -12830,6 +12830,12 @@ msgstr "" "domácím adresářem WeeChat (\"~/.weechat\" je výchozí); jsou povoleny " "specifikátory data (viz. man strftime)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/de.po b/po/de.po index c3799f933..77bfc699a 100644 --- a/po/de.po +++ b/po/de.po @@ -24,7 +24,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-10-03 15:25+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -15009,6 +15009,12 @@ msgstr "" "ersetzt (Standardpfad: \"~/.weechat\") (Hinweis: Inhalt wird evaluiert, " "siehe /help eval)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/po/es.po b/po/es.po index 8473cdb7a..f36a0e7d8 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:31+0200\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -13114,6 +13114,12 @@ msgstr "" "reemplazado por el directorio raíz de WeeChat (\"~/.weechat\" por defecto); " "especificadores de fecha son permitidos (ver man strftime)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/fr.po b/po/fr.po index b52f22ee2..ee44b3978 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" -"PO-Revision-Date: 2019-10-04 20:43+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" +"PO-Revision-Date: 2019-10-05 18:02+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -14702,6 +14702,15 @@ msgstr "" "remplacé par le répertoire de base WeeChat (par défaut : \"~/.weechat\") " "(note : le contenu est évalué, voir /help eval)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" +"suffixe de fichier temporaire utilisé pendant le transfert pour un fichier " +"reçu, il est supprimé après un transfert réussi ; si chaîne vide, aucun " +"suffixe de fichier n'est utilisé pendant le transfert" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/po/hu.po b/po/hu.po index 76ca4a6c4..ebb370712 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:31+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -12087,6 +12087,12 @@ msgstr "" "modulok elérési útvonala ('%h' helyére automatikusan a WeeChat saját " "könyvtára, alapértelmezésben ~/.weechat, kerül)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/it.po b/po/it.po index 1be2e5951..f99fe78bf 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:31+0200\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -13333,6 +13333,12 @@ msgstr "" "sostituito dalla directory home di WeeChat (predefinita è \"~/.weechat); " "sono ammessi gli specificatori di data (consultare man strftime)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/ja.po b/po/ja.po index 299fe4a8b..f98447d4f 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-09-22 18:54+0200\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" "Language-Team: Polish \n" @@ -14358,6 +14358,12 @@ msgstr "" "ciągu zostanie zastąpione przez katalog domowy WeeChat (domyślnie \"~/." "weechat\") (uwaga: zawartość jest przetwarzana, zobacz /help eval)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/po/pt.po b/po/pt.po index 08344a153..358bb4933 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-09-22 18:54+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -13992,6 +13992,12 @@ msgstr "" "substituído pelo diretório do WeeChat (\"~/.weechat\" por omissão) (nota: o " "conteúdo é avaliado, ver /help eval)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/po/pt_BR.po b/po/pt_BR.po index 20ee02e44..c159b59a7 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:32+0200\n" "Last-Translator: Eduardo Elias \n" "Language-Team: weechat-dev \n" @@ -12562,6 +12562,12 @@ msgstr "" "será substituído pelo diretório do WeeChat (\"~/.weechat\" por padrão); " "especificadores de data são permitidos (veja \"man strftime\")" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/ru.po b/po/ru.po index 016933230..e47345da9 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:32+0200\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -12121,6 +12121,12 @@ msgstr "" "путь поиска pluginов ('%h' заменяется на домашний каталог WeeChat, по " "умолчанию - ~/.weechat)" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + #, fuzzy msgid "" "path for reading files when sending (when no path is specified by user): \"%h" diff --git a/po/tr.po b/po/tr.po index 3c37171fc..d01f231e9 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2019-05-13 21:32+0200\n" "Last-Translator: Hasan Kiran \n" "Language-Team: weechat-dev \n" @@ -11066,6 +11066,12 @@ msgid "" "see /help eval)" msgstr "" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/po/weechat.pot b/po/weechat.pot index 0b0b909ef..5f2de5a9e 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2019-10-04 20:38+0200\n" +"POT-Creation-Date: 2019-10-05 18:01+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -10890,6 +10890,12 @@ msgid "" "see /help eval)" msgstr "" +msgid "" +"temporary filename suffix used during the transfer for a file received, it " +"is removed after successful transfer; if empty string, no filename suffix is " +"used during the transfer" +msgstr "" + msgid "" "path for reading files when sending (when no path is specified by user): \"%h" "\" at beginning of string is replaced by WeeChat home (\"~/.weechat\" by " diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c index ddab21d82..f36fb2d46 100644 --- a/src/plugins/xfer/xfer-config.c +++ b/src/plugins/xfer/xfer-config.c @@ -64,6 +64,7 @@ struct t_config_option *xfer_config_file_auto_rename; struct t_config_option *xfer_config_file_auto_resume; struct t_config_option *xfer_config_file_convert_spaces; struct t_config_option *xfer_config_file_download_path; +struct t_config_option *xfer_config_file_download_temporary_suffix; struct t_config_option *xfer_config_file_upload_path; struct t_config_option *xfer_config_file_use_nick_in_filename; @@ -385,6 +386,14 @@ xfer_config_init () "(note: content is evaluated, see /help eval)"), NULL, 0, 0, "%h/xfer", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + xfer_config_file_download_temporary_suffix = weechat_config_new_option ( + xfer_config_file, ptr_section, + "download_temporary_suffix", "string", + N_("temporary filename suffix used during the transfer for a file " + "received, it is removed after successful transfer; " + "if empty string, no filename suffix is used during the transfer"), + NULL, 0, 0, ".part", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); xfer_config_file_upload_path = weechat_config_new_option ( xfer_config_file, ptr_section, "upload_path", "string", diff --git a/src/plugins/xfer/xfer-config.h b/src/plugins/xfer/xfer-config.h index 2a31f0408..edda24985 100644 --- a/src/plugins/xfer/xfer-config.h +++ b/src/plugins/xfer/xfer-config.h @@ -52,6 +52,7 @@ extern struct t_config_option *xfer_config_file_auto_resume; extern struct t_config_option *xfer_config_file_auto_check_crc32; extern struct t_config_option *xfer_config_file_convert_spaces; extern struct t_config_option *xfer_config_file_download_path; +extern struct t_config_option *xfer_config_file_download_temporary_suffix; extern struct t_config_option *xfer_config_file_upload_path; extern struct t_config_option *xfer_config_file_use_nick_in_filename; diff --git a/src/plugins/xfer/xfer-dcc.c b/src/plugins/xfer/xfer-dcc.c index 13306c96d..593235d6a 100644 --- a/src/plugins/xfer/xfer-dcc.c +++ b/src/plugins/xfer/xfer-dcc.c @@ -255,7 +255,7 @@ xfer_dcc_resume_hash (struct t_xfer *xfer) while (fd <= 0) { - fd = open (xfer->local_filename, O_RDONLY); + fd = open (xfer->temp_local_filename, O_RDONLY); if (fd < 0) { if (errno == EINTR) diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index ebed633f9..e9b7b0f26 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -70,6 +70,135 @@ xfer_file_resume (struct t_xfer *xfer, const char *filename) return 0; } +/* + * Checks if file can be downloaded with a given suffix index (if 0 the + * filename is unchanged, otherwise .1, .2, etc. are added to the filename). + * + * Returns 1 if the file can be downloaded with this suffix, 0 if it can not. + */ + +int +xfer_file_check_suffix (struct t_xfer *xfer, int suffix) +{ + char *new_filename, *new_temp_filename; + const char *ptr_suffix; + int rc, length_suffix, length, filename_exists, temp_filename_exists; + int same_files; + + rc = 0; + new_filename = NULL; + new_temp_filename = NULL; + + ptr_suffix = weechat_config_string ( + xfer_config_file_download_temporary_suffix); + length_suffix = (ptr_suffix) ? strlen (ptr_suffix) : 0; + + /* build filename with suffix */ + if (suffix == 0) + { + new_filename = strdup (xfer->local_filename); + } + else + { + length = strlen (xfer->local_filename) + 16 + 1; + new_filename = malloc (length); + if (new_filename) + { + snprintf (new_filename, length, "%s.%d", + xfer->local_filename, + suffix); + } + } + if (!new_filename) + goto error; + + /* build temp filename with suffix */ + length = strlen (new_filename) + length_suffix + 1; + new_temp_filename = malloc (length); + if (!new_temp_filename) + goto error; + snprintf (new_temp_filename, length, + "%s%s", + new_filename, + (ptr_suffix) ? ptr_suffix : ""); + + filename_exists = (access (new_filename, F_OK) == 0); + temp_filename_exists = (access (new_temp_filename, F_OK) == 0); + same_files = (length_suffix == 0); + + /* if both filenames don't exist, we can use this prefix */ + if (!filename_exists && !temp_filename_exists) + goto use_prefix; + + /* + * we try to resume if one of this condition is true: + * - filename == temp filename and it exists + * - filename != temp filename and only the temp filename exists + * in any other case, we skip this suffix index + */ + + if ((same_files && filename_exists) + || (!same_files && !filename_exists && temp_filename_exists)) + { + if (xfer_file_resume (xfer, new_temp_filename)) + goto use_prefix; + } + + /* we skip this suffix index */ + goto end; + +use_prefix: + free (xfer->local_filename); + xfer->local_filename = new_filename; + xfer->temp_local_filename = new_temp_filename; + return 1; + +error: + /* + * in case of error, we remove the local filename and return 1 to stop the + * infinite loop used to find a suffix index + */ + free (xfer->local_filename); + xfer->local_filename = NULL; + rc = 1; + +end: + if (new_filename) + free (new_filename); + if (new_temp_filename) + free (new_temp_filename); + return rc; +} + +/* + * Finds the suffix needed for a file, if the file already exists. + * + * If no suffix is needed, nothing is changed in the xfer. + * If a suffix is needed, temp_local_filename and local_filename are changed + * and filename_suffix is set with the suffix number (starts to 1). + */ + +void +xfer_file_find_suffix (struct t_xfer *xfer) +{ + if (xfer_file_check_suffix (xfer, 0)) + return; + + /* if auto rename is not set, then abort xfer */ + if (!xfer_config_file_auto_rename) + { + xfer_close (xfer, XFER_STATUS_FAILED); + xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); + return; + } + + /* loop until we find a suffix we can use, starting with suffix == 1 */ + xfer->filename_suffix = 0; + while (!xfer_file_check_suffix (xfer, ++xfer->filename_suffix)) + { + } +} + /* * Searches for local filename for a xfer. * @@ -80,8 +209,7 @@ xfer_file_resume (struct t_xfer *xfer, const char *filename) void xfer_file_find_filename (struct t_xfer *xfer) { - char *dir_separator, *path, *filename2; - int length; + char *dir_separator, *path; if (!XFER_IS_FILE(xfer->type)) return; @@ -119,49 +247,7 @@ xfer_file_find_filename (struct t_xfer *xfer) free (path); - /* file already exists? */ - if (access (xfer->local_filename, F_OK) == 0) - { - if (xfer_file_resume (xfer, xfer->local_filename)) - return; - - /* if auto rename is not set, then abort xfer */ - if (!xfer_config_file_auto_rename) - { - xfer_close (xfer, XFER_STATUS_FAILED); - xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); - return; - } - - length = strlen (xfer->local_filename) + 16; - filename2 = malloc (length); - if (!filename2) - { - xfer_close (xfer, XFER_STATUS_FAILED); - xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); - return; - } - xfer->filename_suffix = 0; - do - { - xfer->filename_suffix++; - snprintf (filename2, length, "%s.%d", - xfer->local_filename, - xfer->filename_suffix); - if (access (filename2, F_OK) == 0) - { - if (xfer_file_resume (xfer, filename2)) - break; - } - else - break; - } - while (1); - - free (xfer->local_filename); - xfer->local_filename = strdup (filename2); - free (filename2); - } + xfer_file_find_suffix (xfer); } /* diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c index ac23ac619..c19f0cd1a 100644 --- a/src/plugins/xfer/xfer-network.c +++ b/src/plugins/xfer/xfer-network.c @@ -290,12 +290,16 @@ xfer_network_recv_file_fork (struct t_xfer *xfer) return; if (xfer->start_resume > 0) - xfer->file = open (xfer->local_filename, + { + xfer->file = open (xfer->temp_local_filename, O_APPEND | O_WRONLY | O_NONBLOCK); + } else - xfer->file = open (xfer->local_filename, + { + xfer->file = open (xfer->temp_local_filename, O_CREAT | O_TRUNC | O_WRONLY | O_NONBLOCK, 0644); + } switch (pid = fork ()) { diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 680806318..1ab27ea90 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -346,17 +346,26 @@ xfer_close (struct t_xfer *xfer, enum t_xfer_status status) || (xfer->status == XFER_STATUS_ABORTED)) && XFER_IS_FILE(xfer->type) && XFER_IS_RECV(xfer->type) - && xfer->local_filename + && xfer->temp_local_filename && xfer->pos == 0) { /* erase file only if really empty on disk */ - if (stat (xfer->local_filename, &st) != -1) + if (stat (xfer->temp_local_filename, &st) != -1) { if ((unsigned long long) st.st_size == 0) - unlink (xfer->local_filename); + unlink (xfer->temp_local_filename); } } + /* rename received file if it has a suffix */ + if ((xfer->status == XFER_STATUS_DONE) + && XFER_IS_FILE(xfer->type) + && XFER_IS_RECV(xfer->type) + && (strcmp (xfer->local_filename, xfer->temp_local_filename) != 0)) + { + rename (xfer->temp_local_filename, xfer->local_filename); + } + if (XFER_IS_FILE(xfer->type)) xfer_file_calculate_speed (xfer, 1); @@ -500,6 +509,7 @@ xfer_alloc () new_xfer->unterminated_message = NULL; new_xfer->file = -1; new_xfer->local_filename = NULL; + new_xfer->temp_local_filename = NULL; new_xfer->filename_suffix = -1; new_xfer->pos = 0; new_xfer->ack = 0; @@ -955,6 +965,8 @@ xfer_free (struct t_xfer *xfer) free (xfer->unterminated_message); if (xfer->local_filename) free (xfer->local_filename); + if (xfer->temp_local_filename) + free (xfer->temp_local_filename); if (xfer->hash_handle) { gcry_md_close (*xfer->hash_handle); @@ -1688,6 +1700,8 @@ xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer) return 0; if (!weechat_infolist_new_var_string (ptr_item, "local_filename", xfer->local_filename)) return 0; + if (!weechat_infolist_new_var_string (ptr_item, "temp_local_filename", xfer->temp_local_filename)) + return 0; if (!weechat_infolist_new_var_integer (ptr_item, "filename_suffix", xfer->filename_suffix)) return 0; snprintf (value, sizeof (value), "%llu", xfer->pos); @@ -1776,6 +1790,7 @@ xfer_print_log () weechat_log_printf (" unterminated_message. . : '%s'", ptr_xfer->unterminated_message); weechat_log_printf (" file. . . . . . . . . . : %d", ptr_xfer->file); weechat_log_printf (" local_filename. . . . . : '%s'", ptr_xfer->local_filename); + weechat_log_printf (" temp_local_filename . . : '%s'", ptr_xfer->temp_local_filename); weechat_log_printf (" filename_suffix . . . . : %d", ptr_xfer->filename_suffix); weechat_log_printf (" pos . . . . . . . . . . : %llu", ptr_xfer->pos); weechat_log_printf (" ack . . . . . . . . . . : %llu", ptr_xfer->ack); diff --git a/src/plugins/xfer/xfer.h b/src/plugins/xfer/xfer.h index 263b885ff..ce984c458 100644 --- a/src/plugins/xfer/xfer.h +++ b/src/plugins/xfer/xfer.h @@ -170,6 +170,9 @@ struct t_xfer char *unterminated_message; /* beginning of a message */ int file; /* local file (read or write) */ char *local_filename; /* local filename (with path) */ + char *temp_local_filename; /* local filename filename with */ + /* temp. suffix (during transfer, */ + /* for receive file only) */ int filename_suffix; /* suffix (like .1) if renaming file */ unsigned long long pos; /* number of bytes received/sent */ unsigned long long ack; /* number of bytes received OK */