From ce2c615907533f33d2e481618a3e7218c54908a5 Mon Sep 17 00:00:00 2001 From: liuchengyu Date: Fri, 12 Jan 2024 15:52:07 +0800 Subject: [PATCH] fix: without errno in log or status when open and read file failed(#2287, #2292) --- include/rsync_server.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/rsync_server.h b/include/rsync_server.h index d01cb47c8d..4b3249c5bd 100644 --- a/include/rsync_server.h +++ b/include/rsync_server.h @@ -8,6 +8,8 @@ #include #include +#include +#include #include "net/include/net_conn.h" #include "net/include/net_thread.h" @@ -104,7 +106,7 @@ class RsyncReader { const size_t count, char* data, size_t* bytes_read, std::string* checksum, bool* is_eof) { std::lock_guard guard(mu_); - pstd::Status s = Seek(filepath, offset); + pstd::Status s = readAheadFromOffset(filepath, offset); if (!s.ok()) { return s; } @@ -116,7 +118,7 @@ class RsyncReader { return pstd::Status::OK(); } private: - pstd::Status Seek(const std::string filepath, const size_t offset) { + pstd::Status readAheadFromOffset(const std::string filepath, const size_t offset) { if (filepath == filepath_ && offset >= start_offset_ && offset < end_offset_) { return pstd::Status::OK(); } @@ -124,7 +126,8 @@ class RsyncReader { Reset(); fd_ = open(filepath.c_str(), O_RDONLY); if (fd_ < 0) { - return pstd::Status::IOError("fd open failed"); + LOG(ERROR) << "open file [" << filepath << "] failed! error: " << strerror(errno); + return pstd::Status::IOError("open file [" + filepath + "] failed! error: " + strerror(errno)); } filepath_ = filepath; struct stat buf; @@ -146,9 +149,9 @@ class RsyncReader { } } if (bytesin < 0) { - LOG(ERROR) << "unable to read from " << filepath_; + LOG(ERROR) << "unable to read from " << filepath << ". error: " << strerror(errno); Reset(); - return pstd::Status::IOError("unable to read from " + filepath); + return pstd::Status::IOError("unable to read from " + filepath + ". error: " + strerror(errno)); } end_offset_ = start_offset_ + (ptr - block_data_); return pstd::Status::OK();