commit a7afb4c0d03a71aeb67e9690f7e79396b542caff
parent 066d34a88acb47e6af837f501cac73e677f06eac
Author: Jacki <jacki@thejackimonster.de>
Date: Fri, 26 Apr 2024 02:28:55 +0200
Skip copy for file previews if no extra decryption is necessary
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
2 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c
@@ -25,6 +25,8 @@
#include "gnunet_chat_file.h"
#include "gnunet_chat_context.h"
+#include "gnunet_chat_handle.h"
+
#include <gnunet/gnunet_common.h>
#include <string.h>
@@ -166,13 +168,32 @@ file_destroy (struct GNUNET_CHAT_File *file)
{
GNUNET_assert(file);
- if (file->preview)
- {
+ struct GNUNET_CHAT_FileUpload *upload;
+ struct GNUNET_CHAT_FileDownload *download;
+ struct GNUNET_CHAT_FileUnindex *unindex;
+
+ if (!(file->preview))
+ goto skip_preview;
+
+ if (!(file->key))
+ goto skip_filename;
+
+ char *filename = handle_create_file_path(
+ file->handle, &(file->hash)
+ );
+
+ if (!filename)
+ goto skip_filename;
+
+ if (0 != strcmp(filename, file->preview))
remove(file->preview);
- GNUNET_free(file->preview);
- }
- struct GNUNET_CHAT_FileUpload *upload;
+ GNUNET_free(filename);
+
+skip_filename:
+ GNUNET_free(file->preview);
+
+skip_preview:
while (file->upload_head)
{
upload = file->upload_head;
@@ -186,7 +207,6 @@ file_destroy (struct GNUNET_CHAT_File *file)
GNUNET_free(upload);
}
- struct GNUNET_CHAT_FileDownload *download;
while (file->download_head)
{
download = file->download_head;
@@ -200,7 +220,6 @@ file_destroy (struct GNUNET_CHAT_File *file)
GNUNET_free(download);
}
- struct GNUNET_CHAT_FileUnindex *unindex;
while (file->unindex_head)
{
unindex = file->unindex_head;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -2473,6 +2473,12 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file)
if (GNUNET_YES != GNUNET_DISK_file_test(filename))
goto free_filename;
+ if (!(file->key))
+ {
+ file->preview = filename;
+ return file->preview;
+ }
+
file->preview = GNUNET_DISK_mktemp(
file->name? file->name : ""
);
@@ -2483,8 +2489,8 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file)
remove(file->preview);
if ((GNUNET_OK != GNUNET_DISK_file_copy(filename, file->preview)) ||
- ((file->key) && (GNUNET_OK != util_decrypt_file(file->preview,
- &(file->hash), file->key))))
+ (GNUNET_OK != util_decrypt_file(file->preview,
+ &(file->hash), file->key)))
{
GNUNET_free(file->preview);
file->preview = NULL;
@@ -2504,8 +2510,22 @@ GNUNET_CHAT_file_close_preview (struct GNUNET_CHAT_File *file)
if ((!file) || (!(file->preview)))
return;
- remove(file->preview);
+ if (!(file->key))
+ goto skip_filename;
+
+ char *filename = handle_create_file_path(
+ file->handle, &(file->hash)
+ );
+
+ if (!filename)
+ goto skip_filename;
+
+ if (0 != strcmp(filename, file->preview))
+ remove(file->preview);
+
+ GNUNET_free(filename);
+skip_filename:
GNUNET_free(file->preview);
file->preview = NULL;
}