Skip to content

Commit

Permalink
fix: without errno in log or status when open and read file failed(Op…
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengyu committed Jan 12, 2024
1 parent 73687f3 commit 4d9d9ac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions include/rsync_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include "net/include/net_conn.h"
#include "net/include/net_thread.h"
Expand Down Expand Up @@ -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<std::mutex> guard(mu_);
pstd::Status s = Seek(filepath, offset);
pstd::Status s = readAhead(filepath, offset);
if (!s.ok()) {
return s;
}
Expand All @@ -116,15 +118,16 @@ class RsyncReader {
return pstd::Status::OK();
}
private:
pstd::Status Seek(const std::string filepath, const size_t offset) {
pstd::Status readAhead(const std::string filepath, const size_t offset) {
if (filepath == filepath_ && offset >= start_offset_ && offset < end_offset_) {
return pstd::Status::OK();
}
if (filepath != filepath_) {
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;
Expand All @@ -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();
Expand Down

0 comments on commit 4d9d9ac

Please sign in to comment.