From b677cfe8c261bae436d3e70a45256d79cfda28e3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Sep 2022 22:58:14 +0200 Subject: Remove linux specific sendfile function (unused) --- TODO | 3 ++- include/AsyncImageLoader.hpp | 2 +- src/AsyncImageLoader.cpp | 37 +++---------------------------------- src/plugins/Matrix.cpp | 2 +- 4 files changed, 7 insertions(+), 37 deletions(-) diff --git a/TODO b/TODO index ef5e678..36314ea 100644 --- a/TODO +++ b/TODO @@ -232,4 +232,5 @@ Instead of having an option to disable rounded corners, add an option to set cor Support proper emoji, maybe a different emoji per image. Consider adding an option to use external sxiv, imv etc instead of mpv/quickmedia image viewer. Fallback to playing videos/etc from origin homeserver in matrix if the file is larger than the users homeserver allows. This wont work with pantalaimon + encrypted rooms, so it should be delayed until quickmedia supports matrix encryption. -Fix 4chan posting! cloudflare broke shit. Then create external captcha solver program that solves captcha from captcha image. \ No newline at end of file +Fix 4chan posting! cloudflare broke shit. Then create external captcha solver program that solves captcha from captcha image. +Add option to use invidious, and the invidious front page. \ No newline at end of file diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp index c482a3a..986430c 100644 --- a/include/AsyncImageLoader.hpp +++ b/include/AsyncImageLoader.hpp @@ -39,7 +39,7 @@ namespace QuickMedia { // If |symlink_if_no_resize| is false then a copy is made from |thumbnail_path| to |thumbnail_path_resized| instead of a symlink if |thumbnail_path| is not larger than |resize_target_size|. // One example of why you might not want a symlink is if |thumbnail_path| is a temporary file. - bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type, bool symlink_if_no_resize); + bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type); constexpr int NUM_IMAGE_DOWNLOAD_PARALLEL = 4; constexpr int NUM_IMAGE_LOAD_PARALLEL = 4; diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 883073f..09c01df 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -32,7 +31,7 @@ namespace QuickMedia { return exec_program(args, nullptr, nullptr) == 0; } - bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type, bool symlink_if_no_resize) { + bool create_thumbnail(const Path &thumbnail_path, const Path &thumbnail_path_resized, mgl::vec2i resize_target_size, ContentType content_type) { Path input_path = thumbnail_path; if(content_type == ContentType::IMAGE_WEBP) { @@ -75,42 +74,12 @@ namespace QuickMedia { _exit(0); else _exit(1); - } else if(symlink_if_no_resize) { + } else { int res = symlink(thumbnail_path.data.c_str(), result_path_tmp.data.c_str()); if(res == -1 && errno != EEXIST) { fprintf(stderr, "Failed to symlink %s to %s\n", result_path_tmp.data.c_str(), thumbnail_path.data.c_str()); _exit(1); } - } else { - // TODO: When mac is supported (or other OS than linux), then fix this for them. Mac for example needs fcopyfile instead of sendfile - int input_file = open(thumbnail_path.data.c_str(), O_RDONLY); - if(input_file == -1) { - fprintf(stderr, "Failed to save %s\n", thumbnail_path_resized.data.c_str()); - _exit(1); - } - - int output_file = creat(result_path_tmp.data.c_str(), 0660); - if(output_file == -1) { - fprintf(stderr, "Failed to save %s\n", thumbnail_path_resized.data.c_str()); - _exit(1); - } - - off_t bytes_copied = 0; - struct stat file_stat; - memset(&file_stat, 0, sizeof(file_stat)); - if(fstat(input_file, &file_stat) == -1) { - fprintf(stderr, "Failed to save %s\n", thumbnail_path_resized.data.c_str()); - _exit(1); - } - - // No need to retry, small files - if(sendfile(output_file, input_file, &bytes_copied, file_stat.st_size) == -1) { - fprintf(stderr, "Failed to save %s\n", thumbnail_path_resized.data.c_str()); - _exit(1); - } - - close(input_file); - close(output_file); } } else { mgl::vec2i clamped_size = clamp_to_size(image.get_size(), mgl::vec2i(resize_target_size.x, resize_target_size.y)); @@ -178,7 +147,7 @@ namespace QuickMedia { return; } - if(create_thumbnail(thumbnail_path, thumbnail_path_resized, resize_target_size, file_analyzer.get_content_type(), true)) { + if(create_thumbnail(thumbnail_path, thumbnail_path_resized, resize_target_size, file_analyzer.get_content_type())) { thumbnail_data->loading_state = LoadingState::READY_TO_LOAD; } else { fprintf(stderr, "Failed to convert %s to a thumbnail\n", thumbnail_path.data.c_str()); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index b54092e..f8ee2a2 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -3742,7 +3742,7 @@ namespace QuickMedia { int tmp_file = mkstemp(tmp_filename); if(tmp_file != -1) { std::string thumbnail_path; - if(create_thumbnail(filepath, tmp_filename, thumbnail_max_size, file_analyzer.get_content_type(), true)) + if(create_thumbnail(filepath, tmp_filename, thumbnail_max_size, file_analyzer.get_content_type())) thumbnail_path = tmp_filename; else thumbnail_path = filepath; -- cgit v1.2.3