Commit 6d4c05da authored by Kenton Varda's avatar Kenton Varda Committed by Kenton Varda

Merge OsHandle into FsNode.

parent e3c4dd6f
......@@ -1398,7 +1398,7 @@ protected:
#define FSNODE_METHODS(classname) \
Maybe<int> getFd() override { return DiskHandle::getFd(); } \
\
Own<OsHandle> cloneOsHandle() override { \
Own<FsNode> cloneFsNode() override { \
return heap<classname>(DiskHandle::clone()); \
} \
\
......
......@@ -704,7 +704,7 @@ class InMemoryFile final: public File, public Refcounted {
public:
InMemoryFile(Clock& clock): clock(clock), lastModified(clock.now()) {}
Own<OsHandle> cloneOsHandle() override {
Own<FsNode> cloneFsNode() override {
return addRef(*this);
}
......@@ -892,7 +892,7 @@ public:
InMemoryDirectory(Clock& clock)
: clock(clock), lastModified(clock.now()) {}
Own<OsHandle> cloneOsHandle() override {
Own<FsNode> cloneFsNode() override {
return addRef(*this);
}
......@@ -1555,7 +1555,7 @@ class AppendableFileImpl final: public AppendableFile {
public:
AppendableFileImpl(Own<File>&& fileParam): file(kj::mv(fileParam)) {}
Own<OsHandle> cloneOsHandle() override {
Own<FsNode> cloneFsNode() override {
return heap<AppendableFileImpl>(file->clone());
}
......
......@@ -241,9 +241,11 @@ private:
// L1). You can't do asynchronous RAM access so why asynchronous filesystem? The only way to
// parallelize these is using threads.
class OsHandle {
class FsNode {
// Base class for filesystem node types.
public:
Own<OsHandle> clone();
Own<FsNode> clone();
// Creates a new object of exactly the same type as this one, pointing at exactly the same
// external object.
//
......@@ -252,19 +254,6 @@ public:
virtual Maybe<int> getFd() = 0;
// Get the underlying file descriptor, if any. Returns nullptr if this object actually isn't
// wrapping a file descriptor.
//
// TODO(now): Do we really want everything inheriting OsHandle or should people dynamic_cast to
// it? What about people without RTTI?
protected:
virtual Own<OsHandle> cloneOsHandle() = 0;
// Implements clone(). Required to return an object with exactly the same type as this one.
// Hence, every subclass must implement this.
};
class FsNode: public OsHandle {
public:
Own<FsNode> clone();
enum class Type {
FILE,
......@@ -310,6 +299,11 @@ public:
// into the filesystem (*after* syncing the data), so than incomplete data is never visible to
// other processes. (In practice this works by writing into a temporary file and then rename()ing
// it.)
protected:
virtual Own<FsNode> cloneFsNode() = 0;
// Implements clone(). Required to return an object with exactly the same type as this one.
// Hence, every subclass must implement this.
};
class ReadableFile: public FsNode {
......@@ -888,17 +882,16 @@ inline PathPtr PathPtr::slice(size_t start, size_t end) const {
return PathPtr(parts.slice(start, end));
}
inline Own<OsHandle> OsHandle::clone() { return cloneOsHandle(); }
inline Own<FsNode> FsNode::clone() { return cloneOsHandle().downcast<FsNode>(); }
inline Own<ReadableFile> ReadableFile::clone() { return cloneOsHandle().downcast<ReadableFile>(); }
inline Own<FsNode> FsNode::clone() { return cloneFsNode().downcast<FsNode>(); }
inline Own<ReadableFile> ReadableFile::clone() { return cloneFsNode().downcast<ReadableFile>(); }
inline Own<AppendableFile> AppendableFile::clone() {
return cloneOsHandle().downcast<AppendableFile>();
return cloneFsNode().downcast<AppendableFile>();
}
inline Own<File> File::clone() { return cloneOsHandle().downcast<File>(); }
inline Own<File> File::clone() { return cloneFsNode().downcast<File>(); }
inline Own<ReadableDirectory> ReadableDirectory::clone() {
return cloneOsHandle().downcast<ReadableDirectory>();
return cloneFsNode().downcast<ReadableDirectory>();
}
inline Own<Directory> Directory::clone() { return cloneOsHandle().downcast<Directory>(); }
inline Own<Directory> Directory::clone() { return cloneFsNode().downcast<Directory>(); }
inline void Directory::transfer(
PathPtr toPath, WriteMode toMode, PathPtr fromPath, TransferMode mode) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment