Skip to content

Commit

Permalink
CFEngine no longer relies on rs_file_size()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
larsewi committed Nov 29, 2024
1 parent 5b12f2c commit 234351f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
]
)

Expand Down
21 changes: 20 additions & 1 deletion libcfnet/file_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,25 @@ bool FileStreamServe(SSL *conn, const char *filename)

#define ERROR_MSG_INTERNAL_CLIENT_ERROR "Internal client error"


/**
* @brief Get the size of a file
*
* @param f the file pointer
* @return file size or -1 on error
* @note -1 on error is quite handy, because rs_sig_args() iterprets it as
* file size "Unknown"
*/
static rs_long_t GetFileSize(FILE *f)
{
struct stat st;
if ((fstat(fileno(f), &st) == 0) && S_ISREG(st.st_mode))
{
return st.st_size;
}
return -1;
}

/**
* @brief Compute and send a signature of the basis file
*
Expand Down Expand Up @@ -621,7 +640,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;
Expand Down

0 comments on commit 234351f

Please sign in to comment.