sapling/eden/fs/inodes/TreeEntryFileHandle.cpp
Wez Furlong 25dd9997d9 eden: add FileData::write, enable writes
Summary:
Centralize and delegate most (all?) of the content sensitive portions of file accesses into the FileData class.

Add tests to show that we can write to the overlay file and that the stat data is consistent with the result.

Reviewed By: bolinfest

Differential Revision: D3301251

fbshipit-source-id: a09316ad61c6ef4c656bc5d6dbd43f906abb7932
2016-05-16 14:59:49 -07:00

81 lines
1.9 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 "TreeEntryFileHandle.h"
#include "FileData.h"
#include "TreeEntryFileInode.h"
#include "eden/fs/store/LocalStore.h"
namespace facebook {
namespace eden {
TreeEntryFileHandle::TreeEntryFileHandle(
std::shared_ptr<TreeEntryFileInode> inode,
std::shared_ptr<FileData> data,
int flags)
: inode_(inode), data_(data), openFlags_(flags) {}
TreeEntryFileHandle::~TreeEntryFileHandle() {
// 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> TreeEntryFileHandle::getattr() {
return inode_->getattr();
}
folly::Future<fusell::Dispatcher::Attr> TreeEntryFileHandle::setattr(
const struct stat& attr,
int to_set) {
return inode_->setattr(attr, to_set);
}
bool TreeEntryFileHandle::preserveCache() const {
return true;
}
bool TreeEntryFileHandle::isSeekable() const {
return true;
}
folly::Future<fusell::BufVec> TreeEntryFileHandle::read(
size_t size,
off_t off) {
return data_->read(size, off);
}
folly::Future<size_t> TreeEntryFileHandle::write(
fusell::BufVec&& buf,
off_t off) {
return data_->write(std::move(buf), off);
}
folly::Future<size_t> TreeEntryFileHandle::write(
folly::StringPiece str,
off_t off) {
return data_->write(str, off);
}
folly::Future<folly::Unit> TreeEntryFileHandle::flush(uint64_t lock_owner) {
data_->flush(lock_owner);
return folly::Unit{};
}
folly::Future<folly::Unit> TreeEntryFileHandle::fsync(bool datasync) {
data_->fsync(datasync);
return folly::Unit{};
}
}
}