sapling/eden/fs/inodes/OverlayFile.h
Genevieve Helsel 0f78403480 store weak overlay in OverlayFile
Summary: changes `overlay_` to be stored as a `std::shared_ptr` in order to safely create and pass `std::weak_ptr`s of the overlay to OverlayFiles that are being created.

Reviewed By: chadaustin

Differential Revision: D18302732

fbshipit-source-id: 495b613914771714ba8a8d1beb1c7a0cd72b33d4
2019-11-06 18:24:58 -08:00

45 lines
1.1 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <folly/Expected.h>
#include <folly/File.h>
#include <folly/portability/SysUio.h>
namespace folly {
class File;
}
namespace facebook {
namespace eden {
class Overlay;
class OverlayFile {
public:
OverlayFile() = default;
explicit OverlayFile(folly::File file, std::weak_ptr<Overlay> overlay);
folly::Expected<struct stat, int> fstat() const;
folly::Expected<ssize_t, int> preadNoInt(void* buf, size_t n, off_t offset)
const;
folly::Expected<off_t, int> lseek(off_t offset, int whence) const;
folly::Expected<ssize_t, int>
pwritev(const iovec* iov, int iovcnt, off_t offset) const;
folly::Expected<int, int> ftruncate(off_t length) const;
folly::Expected<int, int> fsync() const;
folly::Expected<int, int> fdatasync() const;
folly::Expected<std::string, int> readFile() const;
private:
folly::File file_;
std::weak_ptr<Overlay> overlay_;
};
} // namespace eden
} // namespace facebook