sapling/eden/fs/inodes/FileHandle.cpp
Adam Simpkins 0e613bd96b rename TreeEntryFileInode to FileInode
Summary:
Rename TreeEntryFileInode to FileInode, and TreeEntryFileHandle to FileHandle.
These class names were long and awkward.

It's slightly unfortunate that we now have classes named both
eden::fuse::FileInode and eden::fuse::fusell::FileInode, but I don't believe
this should cause any major problems.  If we want to eliminate these name
collisions in the future I would advocate for renaming the fusell versions to
something like "FileInodeIface".

Reviewed By: bolinfest

Differential Revision: D4217909

fbshipit-source-id: 899672a318d7ae39595f2c18e171f8fd6cebedc6
2016-11-30 15:49:13 -08:00

88 lines
2.3 KiB
C++

/*
* Copyright (c) 2016, 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 "FileHandle.h"
#include "EdenMount.h"
#include "FileData.h"
#include "FileInode.h"
#include "eden/fs/store/LocalStore.h"
namespace facebook {
namespace eden {
FileHandle::FileHandle(
std::shared_ptr<FileInode> inode,
std::shared_ptr<FileData> data,
int flags)
: inode_(std::move(inode)), data_(std::move(data)), openFlags_(flags) {}
FileHandle::~FileHandle() {
// Must reset the data point prior to calling fileHandleDidClose,
// otherwise it will see a use count that is too high and won't
// reclaim resources soon enough.
data_.reset();
inode_->fileHandleDidClose();
}
folly::Future<fusell::Dispatcher::Attr> FileHandle::getattr() {
return inode_->getattr();
}
folly::Future<fusell::Dispatcher::Attr> FileHandle::setattr(
const struct stat& attr,
int to_set) {
return inode_->setattr(attr, to_set);
}
bool FileHandle::preserveCache() const {
return true;
}
bool FileHandle::isSeekable() const {
return true;
}
folly::Future<fusell::BufVec> FileHandle::read(size_t size, off_t off) {
return data_->read(size, off);
}
folly::Future<size_t> FileHandle::write(fusell::BufVec&& buf, off_t off) {
SCOPE_SUCCESS {
auto myname = inode_->parentInode_->getNameMgr()->resolvePathToNode(
inode_->getNodeId());
inode_->parentInode_->getMount()->getJournal().wlock()->addDelta(
std::make_unique<JournalDelta>(JournalDelta{myname}));
};
return data_->write(std::move(buf), off);
}
folly::Future<size_t> FileHandle::write(folly::StringPiece str, off_t off) {
SCOPE_SUCCESS {
auto myname = inode_->parentInode_->getNameMgr()->resolvePathToNode(
inode_->getNodeId());
inode_->parentInode_->getMount()->getJournal().wlock()->addDelta(
std::make_unique<JournalDelta>(JournalDelta{myname}));
};
return data_->write(str, off);
}
folly::Future<folly::Unit> FileHandle::flush(uint64_t lock_owner) {
data_->flush(lock_owner);
return folly::Unit{};
}
folly::Future<folly::Unit> FileHandle::fsync(bool datasync) {
data_->fsync(datasync);
return folly::Unit{};
}
}
}