sapling/eden/fs/inodes/InodeError.cpp
Chad Austin 8b9261f2a1 run clang-format across all C++ files
Summary:
Per discussion with bolinfest, this brings Eden in line with clang-format.

This diff was generated with `find . \( -iname '*.cpp' -o -iname '*.h' \) -exec bash -c "yes | arc lint {}" \;`

Reviewed By: bolinfest

Differential Revision: D6232695

fbshipit-source-id: d54942bf1c69b5b0dcd4df629f1f2d5538c9e28c
2017-11-03 16:02:03 -07:00

69 lines
1.8 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "InodeError.h"
#include <folly/String.h>
#include "eden/fs/inodes/TreeInode.h"
namespace facebook {
namespace eden {
InodeError::InodeError(int errnum, TreeInodePtr inode, PathComponentPiece child)
: std::system_error(errnum, std::system_category()),
inode_(std::move(inode)),
child_(PathComponent{child}) {}
InodeError::InodeError(
int errnum,
TreeInodePtr inode,
PathComponentPiece child,
std::string&& message)
: std::system_error(errnum, std::system_category()),
inode_(std::move(inode)),
child_(PathComponent{child}),
message_(std::move(message)) {}
const char* InodeError::what() const noexcept {
try {
auto msg = fullMessage_.wlock();
if (msg->empty()) {
*msg = computeMessage();
}
return msg->c_str();
} catch (...) {
// Fallback value if anything goes wrong building the real message
return "<InodeError>";
}
}
std::string InodeError::computeMessage() const {
std::string path;
if (child_.hasValue()) {
if (inode_->getNodeId() == FUSE_ROOT_ID) {
path = child_.value().stringPiece().str();
} else {
path = inode_->getLogPath() + "/";
auto childName = child_.value().stringPiece();
path.append(childName.begin(), childName.end());
}
} else {
path = inode_->getLogPath();
}
if (message_.empty()) {
return path + ": " + folly::errnoStr(errnum()).toStdString();
}
return path + ": " + message_ + ": " +
folly::errnoStr(errnum()).toStdString();
}
} // namespace eden
} // namespace facebook