xfer: add option xfer.file.download_temporary_suffix with default value ".part" (closes #1237)

v2.8-utf8proc
Sébastien Helleu 2019-10-05 18:11:39 +02:00
parent 6c23f632b1
commit 3c0bdc18f3
28 changed files with 317 additions and 65 deletions

View File

@ -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::

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 参照)]
** タイプ: 文字列

View File

@ -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

View File

@ -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 <mimi.vx@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <weechatter@arcor.de>\n"
"Language-Team: German <kde-i18n-de@kde.org>\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 "

View File

@ -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 <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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 "

View File

@ -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 <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <exio4.com@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/weechat/tree/master/"
@ -14123,6 +14123,12 @@ msgstr ""
"フォルトでは \"~/.weechat\" に置換されます) (注意: 内容は評価されます、/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 "

View File

@ -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-09-22 18:54+0200\n"
"Last-Translator: Krzysztof Korościk <soltys@soltys.info>\n"
"Language-Team: Polish <kde-i18n-doc@kde.org>\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 "

View File

@ -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 <vascomalmeida@sapo.pt>\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 "

View File

@ -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 <camponez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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"

View File

@ -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 <sunder67@hotmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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 "

View File

@ -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 <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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 "

View File

@ -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",

View File

@ -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;

View File

@ -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)

View File

@ -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);
}
/*

View File

@ -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 ())
{

View File

@ -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);

View File

@ -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 */