From 8592326a3cbe849e691be6ef108bd495c4319519 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 1 Dec 2021 16:54:38 +0400 Subject: [PATCH] Revert "Use kernel accelerated sendfile to copy files on Linux" This reverts commit 34534a9653fd2308f7b04863f28bb71b741a1890. --- Telegram/SourceFiles/_other/updater_linux.cpp | 33 +++------------ .../platform/linux/specific_linux.cpp | 42 +++---------------- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/Telegram/SourceFiles/_other/updater_linux.cpp b/Telegram/SourceFiles/_other/updater_linux.cpp index 233b102f86..40e887c52e 100644 --- a/Telegram/SourceFiles/_other/updater_linux.cpp +++ b/Telegram/SourceFiles/_other/updater_linux.cpp @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include -#include #include #include #include @@ -98,6 +97,11 @@ bool copyFile(const char *from, const char *to, bool writeprotected) { fclose(ffrom); return false; } + static const int BufSize = 65536; + char buf[BufSize]; + while (size_t size = fread(buf, 1, BufSize, ffrom)) { + fwrite(buf, 1, size, fto); + } struct stat fst; // from http://stackoverflow.com/questions/5486774/keeping-fileowner-and-permissions-after-copying-file-in-c //let's say this wont fail since you already worked OK on that fp @@ -106,33 +110,6 @@ bool copyFile(const char *from, const char *to, bool writeprotected) { fclose(fto); return false; } - - ssize_t copied = sendfile( - fileno(fto), - fileno(ffrom), - nullptr, - fst.st_size); - - if (copied == -1) { - writeLog( - "Copy by sendfile '%s' to '%s' failed, error: %d, fallback now.", - from, - to, - int(errno)); - static const int BufSize = 65536; - char buf[BufSize]; - while (size_t size = fread(buf, 1, BufSize, ffrom)) { - fwrite(buf, 1, size, fto); - } - } else { - writeLog( - "Copy by sendfile '%s' to '%s' done, size: %d, result: %d.", - from, - to, - int(fst.st_size), - int(copied)); - } - //update to the same uid/gid if (!writeprotected && fchown(fileno(fto), fst.st_uid, fst.st_gid) != 0) { fclose(ffrom); diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index b0e90e454b..8a4c8c378d 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -55,9 +55,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#ifdef Q_OS_LINUX -#include -#endif // Q_OS_LINUX #include #include #include @@ -878,14 +875,6 @@ void psNewVersion() { void psSendToMenu(bool send, bool silent) { } -void sendfileFallback(FILE *out, FILE *in) { - static const int BufSize = 65536; - char buf[BufSize]; - while (size_t size = fread(buf, 1, BufSize, in)) { - fwrite(buf, 1, size, out); - } -} - bool linuxMoveFile(const char *from, const char *to) { FILE *ffrom = fopen(from, "rb"), *fto = fopen(to, "wb"); if (!ffrom) { @@ -896,6 +885,11 @@ bool linuxMoveFile(const char *from, const char *to) { fclose(ffrom); return false; } + static const int BufSize = 65536; + char buf[BufSize]; + while (size_t size = fread(buf, 1, BufSize, ffrom)) { + fwrite(buf, 1, size, fto); + } struct stat fst; // from http://stackoverflow.com/questions/5486774/keeping-fileowner-and-permissions-after-copying-file-in-c //let's say this wont fail since you already worked OK on that fp @@ -904,32 +898,6 @@ bool linuxMoveFile(const char *from, const char *to) { fclose(fto); return false; } - -#ifdef Q_OS_LINUX - ssize_t copied = sendfile( - fileno(fto), - fileno(ffrom), - nullptr, - fst.st_size); - if (copied == -1) { - DEBUG_LOG(("Update Error: " - "Copy by sendfile '%1' to '%2' failed, error: %3, fallback now." - ).arg(from - ).arg(to - ).arg(errno)); - sendfileFallback(fto, ffrom); - } else { - DEBUG_LOG(("Update Info: " - "Copy by sendfile '%1' to '%2' done, size: %3, result: %4." - ).arg(from - ).arg(to - ).arg(fst.st_size - ).arg(copied)); - } -#else // Q_OS_LINUX - sendfileFallback(fto, ffrom); -#endif // Q_OS_LINUX - //update to the same uid/gid if (fchown(fileno(fto), fst.st_uid, fst.st_gid) != 0) { fclose(ffrom);