mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
Added type identification capability to InodeBase.
Summary: Added type identification capability to InodeBase and its descendants FileInode and TreeInode. Reviewed By: simpkins Differential Revision: D6564902 fbshipit-source-id: ce9300102d6d6d1c42616eb1e32042f21f6e6cce
This commit is contained in:
parent
bb3994be82
commit
58b472b9d0
@ -26,6 +26,7 @@
|
||||
#include "eden/fs/store/ObjectStore.h"
|
||||
#include "eden/fs/utils/Bug.h"
|
||||
#include "eden/fs/utils/Clock.h"
|
||||
#include "eden/fs/utils/DirType.h"
|
||||
#include "eden/fs/utils/UnboundedQueueThreadPool.h"
|
||||
#include "eden/fs/utils/XAttr.h"
|
||||
|
||||
@ -177,7 +178,7 @@ FileInode::FileInode(
|
||||
PathComponentPiece name,
|
||||
mode_t mode,
|
||||
const folly::Optional<Hash>& hash)
|
||||
: InodeBase(ino, std::move(parentInode), name),
|
||||
: InodeBase(ino, mode_to_dtype(mode), std::move(parentInode), name),
|
||||
state_(
|
||||
folly::in_place,
|
||||
this,
|
||||
@ -194,7 +195,7 @@ FileInode::FileInode(
|
||||
folly::File&& file,
|
||||
timespec ctime,
|
||||
dev_t rdev)
|
||||
: InodeBase(ino, std::move(parentInode), name),
|
||||
: InodeBase(ino, mode_to_dtype(mode), std::move(parentInode), name),
|
||||
state_(folly::in_place, this, mode, ctime, rdev) {}
|
||||
|
||||
folly::Future<fusell::Dispatcher::Attr> FileInode::getattr() {
|
||||
|
@ -29,7 +29,8 @@ InodeBase::~InodeBase() {
|
||||
}
|
||||
|
||||
InodeBase::InodeBase(EdenMount* mount)
|
||||
: ino_(FUSE_ROOT_ID),
|
||||
: ino_{FUSE_ROOT_ID},
|
||||
type_{dtype_t::Dir},
|
||||
mount_{mount},
|
||||
location_{
|
||||
LocationInfo{nullptr,
|
||||
@ -42,11 +43,13 @@ InodeBase::InodeBase(EdenMount* mount)
|
||||
|
||||
InodeBase::InodeBase(
|
||||
fuse_ino_t ino,
|
||||
dtype_t type,
|
||||
TreeInodePtr parent,
|
||||
PathComponentPiece name)
|
||||
: ino_(ino),
|
||||
mount_(parent->mount_),
|
||||
location_(LocationInfo(std::move(parent), name)) {
|
||||
: ino_{ino},
|
||||
type_{type},
|
||||
mount_{parent->mount_},
|
||||
location_{LocationInfo{std::move(parent), name}} {
|
||||
// Inode numbers generally shouldn't be 0.
|
||||
// Older versions of glibc have bugs handling files with an inode number of 0
|
||||
DCHECK_NE(ino_, 0);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "eden/fs/fuse/Dispatcher.h"
|
||||
#include "eden/fs/fuse/fuse_headers.h"
|
||||
#include "eden/fs/inodes/InodePtr.h"
|
||||
#include "eden/fs/utils/DirType.h"
|
||||
#include "eden/fs/utils/PathFuncs.h"
|
||||
|
||||
namespace facebook {
|
||||
@ -31,13 +32,18 @@ class InodeBase {
|
||||
public:
|
||||
/**
|
||||
* Constructor for the root TreeInode of an EdenMount.
|
||||
* type is set to dtype_t::Dir
|
||||
*/
|
||||
explicit InodeBase(EdenMount* mount);
|
||||
|
||||
/**
|
||||
* Constructor for all non-root inodes.
|
||||
*/
|
||||
InodeBase(fuse_ino_t ino, TreeInodePtr parent, PathComponentPiece name);
|
||||
InodeBase(
|
||||
fuse_ino_t ino,
|
||||
dtype_t type,
|
||||
TreeInodePtr parent,
|
||||
PathComponentPiece name);
|
||||
|
||||
virtual ~InodeBase();
|
||||
|
||||
@ -56,6 +62,10 @@ class InodeBase {
|
||||
return ino_;
|
||||
}
|
||||
|
||||
dtype_t getType() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reference count of an inode.
|
||||
*/
|
||||
@ -404,6 +414,8 @@ class InodeBase {
|
||||
|
||||
fuse_ino_t const ino_;
|
||||
|
||||
dtype_t const type_;
|
||||
|
||||
/**
|
||||
* The EdenMount object that this inode belongs to.
|
||||
*
|
||||
|
@ -139,7 +139,7 @@ TreeInode::TreeInode(
|
||||
TreeInodePtr parent,
|
||||
PathComponentPiece name,
|
||||
Dir&& dir)
|
||||
: InodeBase(ino, parent, name), contents_(std::move(dir)) {
|
||||
: InodeBase(ino, dtype_t::Dir, parent, name), contents_(std::move(dir)) {
|
||||
DCHECK_NE(ino, FUSE_ROOT_ID);
|
||||
}
|
||||
|
||||
|
@ -167,6 +167,13 @@ class FileInodeTest : public ::testing::Test {
|
||||
TestMount mount_;
|
||||
};
|
||||
|
||||
TEST_F(FileInodeTest, getType) {
|
||||
auto dir = mount_.getTreeInode("dir/sub");
|
||||
auto regularFile = mount_.getFileInode("dir/a.txt");
|
||||
EXPECT_EQ(dtype_t::Dir, dir->getType());
|
||||
EXPECT_EQ(dtype_t::Regular, regularFile->getType());
|
||||
}
|
||||
|
||||
TEST_F(FileInodeTest, getattrFromBlob) {
|
||||
auto inode = mount_.getFileInode("dir/a.txt");
|
||||
auto attr = getFileAttr(inode);
|
||||
|
@ -47,6 +47,7 @@ TEST_F(SymlinkTest, makeSymlink) {
|
||||
|
||||
auto root = mount_.getTreeInode(RelativePathPiece());
|
||||
auto inode = root->symlink(PathComponentPiece{name}, target);
|
||||
EXPECT_EQ(dtype_t::Symlink, inode->getType());
|
||||
EXPECT_EQ(inode->readlink().get(), target);
|
||||
// Let's make sure that we can load it up and see the right results
|
||||
auto loadedInode = mount_.getFileInode(RelativePathPiece{name});
|
||||
|
@ -29,5 +29,6 @@ cpp_unittest(
|
||||
],
|
||||
external_deps = [
|
||||
("googletest", None, "gmock"),
|
||||
("googletest", None, "gtest"),
|
||||
],
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user