mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-13 16:03:22 -05:00
Improve warning message on open failure.
Before: W0430 08:26:53.958887 41576 moonfire-nvr.cc:123] driveway: Output error; sleeping before retrying: open 031e423c-2a0c-4450-b6cc-8af629606a90: Permission denied After: W0430 08:50:06.315666 43514 moonfire-nvr.cc:123] driveway: Output error; sleeping before retrying: open 98592dfa-4ab4-427a-8ad0-033325f0f0b3 (within dir /home/slamb/moonfire/sample): Permission denied
This commit is contained in:
parent
374975a73c
commit
713d7863de
@ -59,12 +59,15 @@ namespace {
|
||||
|
||||
class RealFile : public File {
|
||||
public:
|
||||
explicit RealFile(int fd) : fd_(fd) {}
|
||||
RealFile(re2::StringPiece name, int fd)
|
||||
: name_(name.data(), name.size()), fd_(fd) {}
|
||||
RealFile(const RealFile &) = delete;
|
||||
void operator=(const RealFile &) = delete;
|
||||
|
||||
~RealFile() final { Close(); }
|
||||
|
||||
const std::string &name() const { return name_; }
|
||||
|
||||
int Access(const char *path, int mode, int flags) final {
|
||||
return faccessat(fd_, path, mode, flags) < 0 ? errno : 0;
|
||||
}
|
||||
@ -106,7 +109,7 @@ class RealFile : public File {
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
f->reset(new RealFile(ret));
|
||||
f->reset(new RealFile(StrCat(name_, "/", path), ret));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -145,6 +148,7 @@ class RealFile : public File {
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
int fd_ = -1;
|
||||
};
|
||||
|
||||
@ -186,7 +190,7 @@ class RealFilesystem : public Filesystem {
|
||||
if (ret < 0) {
|
||||
return errno;
|
||||
}
|
||||
f->reset(new RealFile(ret));
|
||||
f->reset(new RealFile(path, ret));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,9 @@ class File {
|
||||
// Close the file, ignoring the result.
|
||||
virtual ~File() {}
|
||||
|
||||
// A name for the file (typically assigned at open time).
|
||||
virtual const std::string &name() const = 0;
|
||||
|
||||
// faccessat(), returning 0 on success or errno>0 on failure.
|
||||
virtual int Access(const char *path, int mode, int flags) = 0;
|
||||
|
||||
@ -95,6 +98,7 @@ class File {
|
||||
|
||||
class MockFile : public File {
|
||||
public:
|
||||
MOCK_CONST_METHOD0(name, const std::string &());
|
||||
MOCK_METHOD3(Access, int(const char *, int, int));
|
||||
MOCK_METHOD0(Close, int());
|
||||
|
||||
|
@ -143,7 +143,8 @@ bool SampleFileWriter::Open(const char *filename, std::string *error_message) {
|
||||
int ret =
|
||||
parent_dir_->Open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600, &file_);
|
||||
if (ret != 0) {
|
||||
*error_message = StrCat("open ", filename, ": ", strerror(ret));
|
||||
*error_message = StrCat("open ", filename, " (within dir ",
|
||||
parent_dir_->name(), "): ", strerror(ret));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user