From fafd9712e7435edce99495a6ead3f82229f28653 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 29 Nov 2024 11:35:22 +0100 Subject: [PATCH] CFEngine no longer relies on `rs_file_size()` Apparently `rs_file_size()` does not exist (or is not exposed) in previous versions of `librsync`. Hence, we'll make our own implementation in order to make the File Stream API a bit more backwards compatible in terms of `librsync` versions. Ticket: ENT-12414 Changelog: None Signed-off-by: Lars Erik Wik --- configure.ac | 2 +- libcfnet/file_stream.c | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 363e0b6b36..786110371d 100644 --- a/configure.ac +++ b/configure.ac @@ -531,7 +531,7 @@ fi CF3_WITH_LIBRARY(librsync, [ AC_CHECK_HEADERS([librsync.h], [], AC_MSG_ERROR(Cannot find librsync)) - AC_CHECK_LIB(rsync, rs_file_size, [], [AC_MSG_ERROR(Cannot find librsync)]) + AC_CHECK_LIB(rsync, rs_job_iter, [], [AC_MSG_ERROR(Cannot find librsync)]) ] ) diff --git a/libcfnet/file_stream.c b/libcfnet/file_stream.c index ea35caa0ed..4d9237fbc9 100644 --- a/libcfnet/file_stream.c +++ b/libcfnet/file_stream.c @@ -592,6 +592,31 @@ bool FileStreamServe(SSL *conn, const char *filename) #define ERROR_MSG_INTERNAL_CLIENT_ERROR "Internal client error" + +/** + * @brief Get the size of a file + * + * @param file The file pointer + * @return the file size or -1 on error + * @note -1 on error is quite handy, because rs_sig_args() iterprets it as + * unknown file size + */ +static rs_long_t GetFileSize(FILE *file) +{ + int fd = fileno(file); + if (fd == -1) { + return -1; + } + + struct stat sb; + if (fstat(fd, &sb) == -1) + { + return -1; + } + + return S_ISREG(sb.st_mode); +} + /** * @brief Compute and send a signature of the basis file * @@ -621,7 +646,7 @@ static bool SendSignature(SSL *conn, const char *filename) } /* Get file size */ - rs_long_t fsize = rs_file_size(file); + rs_long_t fsize = GetFileSize(file); /* Get recommended arguments */ rs_magic_number sig_magic = 0;