From 2c9ee5ccc509d54e91ba0ace719eef1206153e7e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 21 Oct 2024 16:31:02 +0200 Subject: [PATCH] cf-serverd now stats file every read on network transmission Previously the file was stat'ed every N read to detect if file changes during transmission. The reason for limiting the calls to stat is probably to make the code more efficient. However, there are reasons to believe that the bug experienced in ENT-12033 is attributed to filechanges during transmission. Hence, I'm changing the code to do this for every read, as it better to be safe than fast. Ticket: None Changelog: None Signed-off-by: Lars Erik Wik --- cf-serverd/server_common.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/cf-serverd/server_common.c b/cf-serverd/server_common.c index 6322a1a9d2..5801b9db7d 100644 --- a/cf-serverd/server_common.c +++ b/cf-serverd/server_common.c @@ -403,7 +403,7 @@ static void FailedTransfer(ConnectionInfo *connection) void CfGetFile(ServerFileGetState *args) { int fd; - off_t n_read, total = 0, sendlen = 0, count = 0; + off_t n_read, total = 0, sendlen = 0; char sendbuffer[CF_BUFSIZE + 256], filename[CF_BUFSIZE - 128]; struct stat sb; int blocksize = 2048; @@ -459,13 +459,6 @@ void CfGetFile(ServerFileGetState *args) } else { - int div = 3; - - if (sb.st_size > 10485760L) /* File larger than 10 MB, checks every 64kB */ - { - div = 32; - } - while (true) { memset(sendbuffer, 0, CF_BUFSIZE); @@ -488,14 +481,11 @@ void CfGetFile(ServerFileGetState *args) /* check the file is not changing at source */ - if (count++ % div == 0) /* Don't do this too often */ + if (stat(filename, &sb)) { - if (stat(filename, &sb)) - { - Log(LOG_LEVEL_ERR, "Cannot stat file '%s'. (stat: %s)", - filename, GetErrorStr()); - break; - } + Log(LOG_LEVEL_ERR, "Cannot stat file '%s'. (stat: %s)", + filename, GetErrorStr()); + break; } if (sb.st_size != savedlen)