Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: without errno in log or status when open and read file failed(#2287, #2292) #2307

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading