mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
a6ae3edab9
Summary: This change makes it so that all of the C++ code related to the edenfs daemon is now contained in the eden/fs subdirectory. Reviewed By: bolinfest, wez Differential Revision: D4889053 fbshipit-source-id: d0bd4774cc0bdb5d1d6b6f47d716ecae52391f37
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
/*
|
|
* Copyright (c) 2016-present, 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.
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include <folly/Synchronized.h>
|
|
#include "eden/fs/inodes/TreeInode.h"
|
|
#include "eden/fs/utils/PathFuncs.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
/**
|
|
* ParentInodeInfo contains information about an InodeBase's parent.
|
|
*
|
|
* This object hold the lock on the parent TreeInode's contents for as long as
|
|
* it exists. This ensures that the Inode in question cannot be renamed or
|
|
* unlinked while the ParentInodeInfo object exists.
|
|
*
|
|
* Note that we intentionally hold the parent TreeInode's contents lock, and
|
|
* not this Inode's location_ lock. The location_ lock would also prevent
|
|
* changes to the location, but this lock is very low-level in our lock
|
|
* ordering scheme, and no other locks may be held while holding it. This
|
|
* prevents us from doing many useful operations. Additionally, most
|
|
* operations where we need to use the ParentInodeInfo requires us to hold the
|
|
* parent's lock anyway.
|
|
*/
|
|
class ParentInodeInfo {
|
|
public:
|
|
ParentInodeInfo(
|
|
PathComponentPiece name,
|
|
TreeInodePtr parent,
|
|
bool isUnlinked,
|
|
folly::Synchronized<TreeInode::Dir>::LockedPtr contents)
|
|
: name_(name),
|
|
parent_(std::move(parent)),
|
|
isUnlinked_(isUnlinked),
|
|
parentContents_(std::move(contents)) {}
|
|
|
|
/**
|
|
* Get a pointer to the parent.
|
|
*
|
|
* This will return a null pointer if this the root inode.
|
|
* In all other cases this will return non-null, including for unlinked
|
|
* inodes.
|
|
*
|
|
* For unlinked inodes this returns a pointer to the inode that used to be
|
|
* the parent just before this inode was unlinked. Note that in this case
|
|
* the parent itself may also be unlinked.
|
|
*/
|
|
const TreeInodePtr& getParent() const {
|
|
return parent_;
|
|
}
|
|
|
|
/**
|
|
* Returns true if this inode has been unlinked from its parent.
|
|
*/
|
|
bool isUnlinked() const {
|
|
return isUnlinked_;
|
|
}
|
|
|
|
/**
|
|
* Get the name of this inode inside its parent.
|
|
*
|
|
* For unlinked inodes this returns its name just before it was unlinked.
|
|
*/
|
|
const PathComponent& getName() const {
|
|
return name_;
|
|
}
|
|
|
|
/**
|
|
* Get the locked contents of the parent inode.
|
|
*
|
|
* This returns a null pointer if this is the root inode, or if this inode is
|
|
* unlinked.
|
|
*/
|
|
const folly::Synchronized<TreeInode::Dir>::LockedPtr& getParentContents()
|
|
const {
|
|
return parentContents_;
|
|
}
|
|
|
|
void reset() {
|
|
if (parentContents_) {
|
|
parentContents_.unlock();
|
|
}
|
|
}
|
|
|
|
private:
|
|
PathComponent name_;
|
|
TreeInodePtr parent_;
|
|
bool isUnlinked_;
|
|
folly::Synchronized<TreeInode::Dir>::LockedPtr parentContents_;
|
|
};
|
|
}
|
|
}
|