mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-08-02 09:46:21 +00:00
upstream: fix: Improve status reporting and filename handling for /url save (a9ef00032)
This commit is contained in:
@@ -9312,18 +9312,30 @@ _prepare_filename(ProfWin* window, gchar* url, gchar* path)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the downloads directory exists for saving cleartexts.
|
auto_gchar gchar* expanded_path = path ? get_expanded_path(path) : files_get_download_path(jid);
|
||||||
auto_gchar gchar* downloads_dir = path ? get_expanded_path(path) : files_get_download_path(jid);
|
|
||||||
if (g_mkdir_with_parents(downloads_dir, S_IRWXU) != 0) {
|
// If path is provided and doesn't look like a directory, create its parent.
|
||||||
cons_show_error("Failed to create download directory "
|
// Otherwise, create the directory itself.
|
||||||
"at '%s' with error '%s'",
|
if (path && !g_str_has_suffix(expanded_path, G_DIR_SEPARATOR_S) && !g_file_test(expanded_path, G_FILE_TEST_IS_DIR)) {
|
||||||
downloads_dir, strerror(errno));
|
auto_gchar gchar* dirname = g_path_get_dirname(expanded_path);
|
||||||
return NULL;
|
if (g_mkdir_with_parents(dirname, S_IRWXU) != 0) {
|
||||||
|
cons_show_error("Failed to create download directory "
|
||||||
|
"at '%s' with error '%s'",
|
||||||
|
dirname, strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (g_mkdir_with_parents(expanded_path, S_IRWXU) != 0) {
|
||||||
|
cons_show_error("Failed to create download directory "
|
||||||
|
"at '%s' with error '%s'",
|
||||||
|
expanded_path, strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate an unique filename from the URL that should be stored in the
|
// Generate an unique filename from the URL that should be stored in the
|
||||||
// downloads directory.
|
// downloads directory.
|
||||||
return unique_filename_from_url(url, downloads_dir);
|
return unique_filename_from_url(url, expanded_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
|
|||||||
@@ -106,9 +106,11 @@ aesgcm_file_get(void* userdata)
|
|||||||
http_dl->worker = aesgcm_dl->worker;
|
http_dl->worker = aesgcm_dl->worker;
|
||||||
http_dl->id = strdup(aesgcm_dl->id);
|
http_dl->id = strdup(aesgcm_dl->id);
|
||||||
http_dl->url = strdup(https_url);
|
http_dl->url = strdup(https_url);
|
||||||
|
http_dl->display_url = strdup(aesgcm_dl->url);
|
||||||
http_dl->filename = strdup(tmpname);
|
http_dl->filename = strdup(tmpname);
|
||||||
http_dl->cmd_template = NULL;
|
http_dl->cmd_template = NULL;
|
||||||
http_dl->silent = FALSE;
|
http_dl->silent = FALSE;
|
||||||
|
http_dl->silent_done = TRUE;
|
||||||
http_dl->return_bytes_received = TRUE;
|
http_dl->return_bytes_received = TRUE;
|
||||||
aesgcm_dl->http_dl = http_dl;
|
aesgcm_dl->http_dl = http_dl;
|
||||||
|
|
||||||
@@ -139,10 +141,12 @@ aesgcm_file_get(void* userdata)
|
|||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
"Downloading '%s' failed: Failed to decrypt "
|
"Downloading '%s' failed: Failed to decrypt "
|
||||||
"file (%s).",
|
"file (%s).",
|
||||||
https_url, gcry_strerror(crypt_res));
|
aesgcm_dl->url, gcry_strerror(crypt_res));
|
||||||
} else {
|
} else {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
"Decrypted file saved to '%s'", aesgcm_dl->filename);
|
"Downloading '%s': done\nSaved to '%s'",
|
||||||
|
aesgcm_dl->url, aesgcm_dl->filename);
|
||||||
|
win_mark_received(aesgcm_dl->window, aesgcm_dl->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aesgcm_dl->cmd_template != NULL) {
|
if (aesgcm_dl->cmd_template != NULL) {
|
||||||
|
|||||||
@@ -58,7 +58,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
GSList* download_processes = NULL;
|
GSList* download_processes = NULL;
|
||||||
gboolean silent = FALSE;
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
_xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||||
@@ -84,9 +83,16 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
|||||||
dlperc = (100 * dlnow) / dltotal;
|
dlperc = (100 * dlnow) / dltotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!download->silent) {
|
||||||
http_print_transfer_update(download->window, download->url,
|
const char* url = download->display_url ? download->display_url : download->url;
|
||||||
"Downloading '%s': %d%%", download->url, dlperc);
|
if (dlnow == dltotal && dltotal > 0) {
|
||||||
|
http_print_transfer_update(download->window, download->id,
|
||||||
|
"Downloading '%s': done", url);
|
||||||
|
} else {
|
||||||
|
http_print_transfer_update(download->window, download->id,
|
||||||
|
"Downloading '%s': %d%%", url, dlperc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
|
|
||||||
@@ -111,15 +117,15 @@ http_file_get(void* userdata)
|
|||||||
|
|
||||||
CURL* curl;
|
CURL* curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
silent = download->silent;
|
|
||||||
|
|
||||||
download->cancel = 0;
|
download->cancel = 0;
|
||||||
download->bytes_received = 0;
|
download->bytes_received = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
if (!silent) {
|
const char* display_url = download->display_url ? download->display_url : download->url;
|
||||||
|
if (!download->silent) {
|
||||||
http_print_transfer(download->window, download->id,
|
http_print_transfer(download->window, download->id,
|
||||||
"Downloading '%s': 0%%", download->url);
|
"Downloading '%s': 0%%", display_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* outfh = fopen(download->filename, "wb");
|
FILE* outfh = fopen(download->filename, "wb");
|
||||||
@@ -198,18 +204,18 @@ http_file_get(void* userdata)
|
|||||||
http_print_transfer_update(download->window, download->id,
|
http_print_transfer_update(download->window, download->id,
|
||||||
"Downloading '%s' failed: "
|
"Downloading '%s' failed: "
|
||||||
"Download was canceled",
|
"Download was canceled",
|
||||||
download->url);
|
display_url);
|
||||||
} else {
|
} else {
|
||||||
http_print_transfer_update(download->window, download->id,
|
http_print_transfer_update(download->window, download->id,
|
||||||
"Downloading '%s' failed: %s",
|
"Downloading '%s' failed: %s",
|
||||||
download->url, err);
|
display_url, err);
|
||||||
}
|
}
|
||||||
free(err);
|
free(err);
|
||||||
} else {
|
} else {
|
||||||
if (!download->cancel && !silent) {
|
if (!download->cancel && !download->silent && !download->silent_done) {
|
||||||
http_print_transfer_update(download->window, download->id,
|
http_print_transfer_update(download->window, download->id,
|
||||||
"Downloading '%s': done\nSaved to '%s'",
|
"Downloading '%s': done\nSaved to '%s'",
|
||||||
download->url, download->filename);
|
display_url, download->filename);
|
||||||
win_mark_received(download->window, download->id);
|
win_mark_received(download->window, download->id);
|
||||||
if (download->return_bytes_received) {
|
if (download->return_bytes_received) {
|
||||||
ret = malloc(sizeof(*ret));
|
ret = malloc(sizeof(*ret));
|
||||||
@@ -230,7 +236,7 @@ http_file_get(void* userdata)
|
|||||||
http_print_transfer_update(download->window, download->id,
|
http_print_transfer_update(download->window, download->id,
|
||||||
"Downloading '%s' failed: Unable to call "
|
"Downloading '%s' failed: Unable to call "
|
||||||
"command '%s' with file at '%s' (%s).",
|
"command '%s' with file at '%s' (%s).",
|
||||||
download->url,
|
display_url,
|
||||||
download->cmd_template,
|
download->cmd_template,
|
||||||
download->filename,
|
download->filename,
|
||||||
"TODO: Log the error");
|
"TODO: Log the error");
|
||||||
@@ -247,6 +253,7 @@ out:
|
|||||||
|
|
||||||
free(download->filename);
|
free(download->filename);
|
||||||
free(download->url);
|
free(download->url);
|
||||||
|
free(download->display_url);
|
||||||
free(download->id);
|
free(download->id);
|
||||||
free(download);
|
free(download);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ typedef struct http_download_t
|
|||||||
{
|
{
|
||||||
char* id;
|
char* id;
|
||||||
char* url;
|
char* url;
|
||||||
|
char* display_url;
|
||||||
char* filename;
|
char* filename;
|
||||||
char* cmd_template;
|
char* cmd_template;
|
||||||
curl_off_t bytes_received;
|
curl_off_t bytes_received;
|
||||||
@@ -58,6 +59,7 @@ typedef struct http_download_t
|
|||||||
pthread_t worker;
|
pthread_t worker;
|
||||||
int cancel;
|
int cancel;
|
||||||
gboolean silent;
|
gboolean silent;
|
||||||
|
gboolean silent_done;
|
||||||
gboolean return_bytes_received;
|
gboolean return_bytes_received;
|
||||||
} HTTPDownload;
|
} HTTPDownload;
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,13 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
|||||||
ulperc = (100 * ulnow) / ultotal;
|
ulperc = (100 * ulnow) / ultotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar* msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
|
gchar* msg = NULL;
|
||||||
|
if (ulnow == ultotal && ultotal > 0) {
|
||||||
|
msg = g_strdup_printf("Uploading '%s': done", upload->filename);
|
||||||
|
} else {
|
||||||
|
msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
|
||||||
|
}
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
msg = g_strdup(FALLBACK_MSG);
|
msg = g_strdup(FALLBACK_MSG);
|
||||||
}
|
}
|
||||||
@@ -314,7 +320,7 @@ http_file_put(void* userdata)
|
|||||||
cons_show_error("%s", err_msg);
|
cons_show_error("%s", err_msg);
|
||||||
} else {
|
} else {
|
||||||
if (!upload->cancel) {
|
if (!upload->cancel) {
|
||||||
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
|
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': done", upload->filename);
|
||||||
if (!status_msg) {
|
if (!status_msg) {
|
||||||
status_msg = g_strdup(FALLBACK_MSG);
|
status_msg = g_strdup(FALLBACK_MSG);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user