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 fafd971
Show file tree
Hide file tree
Showing 2 changed files with 27 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
27 changes: 26 additions & 1 deletion libcfnet/file_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning

Code scanning / CodeQL

Boolean type mismatch between function type and return value Warning

Function GetFileSize has return type rs_long_t and returns bool(__S_ISTYPE(mode,mask)=(((mode)=&=__S_IFMT)====(mask)))
}

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

0 comments on commit fafd971

Please sign in to comment.