2016-05-12 23:43:17 +03:00
|
|
|
/*
|
2017-01-21 09:02:33 +03:00
|
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
2016-05-12 23:43:17 +03:00
|
|
|
* 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
|
|
|
|
|
2018-02-17 02:35:30 +03:00
|
|
|
#include "eden/fs/model/Hash.h"
|
2017-04-14 21:31:48 +03:00
|
|
|
#include "eden/fs/utils/PathFuncs.h"
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
#include <folly/String.h>
|
2017-03-17 23:21:33 +03:00
|
|
|
#include <iosfwd>
|
2018-10-24 03:03:11 +03:00
|
|
|
#include <optional>
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
class Hash;
|
|
|
|
|
2018-02-20 22:16:00 +03:00
|
|
|
/**
|
|
|
|
* Represents the allowed types of entries in version control trees.
|
|
|
|
*
|
|
|
|
* Currently missing from this list: git submodules.
|
|
|
|
*/
|
2018-02-17 02:35:28 +03:00
|
|
|
enum class TreeEntryType : uint8_t {
|
|
|
|
TREE,
|
2018-02-16 01:23:07 +03:00
|
|
|
REGULAR_FILE,
|
|
|
|
EXECUTABLE_FILE,
|
|
|
|
SYMLINK,
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
|
|
|
|
2018-02-17 02:35:30 +03:00
|
|
|
/**
|
|
|
|
* Computes an initial mode_t, including permission bits, from a FileType.
|
|
|
|
*/
|
|
|
|
mode_t modeFromTreeEntryType(TreeEntryType ft);
|
|
|
|
|
2018-02-20 22:16:00 +03:00
|
|
|
/**
|
|
|
|
* Converts an arbitrary mode_t to the appropriate TreeEntryType if the file
|
2018-10-24 04:48:38 +03:00
|
|
|
* can be tracked by version control. If not, returns std::nullopt.
|
2018-02-20 22:16:00 +03:00
|
|
|
*/
|
2018-10-24 03:03:11 +03:00
|
|
|
std::optional<TreeEntryType> treeEntryTypeFromMode(mode_t mode);
|
2018-02-20 22:16:00 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
class TreeEntry {
|
|
|
|
public:
|
|
|
|
explicit TreeEntry(
|
|
|
|
const Hash& hash,
|
|
|
|
folly::StringPiece name,
|
2018-02-17 02:35:28 +03:00
|
|
|
TreeEntryType type)
|
|
|
|
: type_(type), hash_(hash), name_(PathComponentPiece(name)) {}
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2018-10-31 21:48:14 +03:00
|
|
|
explicit TreeEntry(
|
|
|
|
const Hash& hash,
|
|
|
|
folly::StringPiece name,
|
|
|
|
TreeEntryType type,
|
|
|
|
std::optional<uint64_t> size,
|
|
|
|
std::optional<Hash> contentSha1)
|
|
|
|
: type_(type),
|
|
|
|
hash_(hash),
|
|
|
|
name_(PathComponentPiece(name)),
|
|
|
|
size_(size),
|
|
|
|
contentSha1_(contentSha1) {}
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
const Hash& getHash() const {
|
|
|
|
return hash_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathComponent& getName() const {
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
2018-02-16 01:23:09 +03:00
|
|
|
bool isTree() const {
|
2018-02-17 02:35:28 +03:00
|
|
|
return type_ == TreeEntryType::TREE;
|
2016-05-12 23:43:17 +03:00
|
|
|
}
|
|
|
|
|
2018-02-17 02:35:28 +03:00
|
|
|
TreeEntryType getType() const {
|
|
|
|
return type_;
|
2016-05-12 23:43:17 +03:00
|
|
|
}
|
|
|
|
|
2017-10-26 02:49:58 +03:00
|
|
|
std::string toLogString() const;
|
|
|
|
|
2018-10-31 21:48:14 +03:00
|
|
|
const std::optional<uint64_t>& getSize() const {
|
|
|
|
return size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::optional<Hash>& getContentSha1() const {
|
|
|
|
return contentSha1_;
|
|
|
|
}
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
private:
|
2018-02-17 02:35:28 +03:00
|
|
|
TreeEntryType type_;
|
2016-07-07 23:35:39 +03:00
|
|
|
Hash hash_;
|
|
|
|
PathComponent name_;
|
2018-10-31 21:48:14 +03:00
|
|
|
std::optional<uint64_t> size_;
|
|
|
|
std::optional<Hash> contentSha1_;
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
2017-03-17 23:21:33 +03:00
|
|
|
|
2018-02-17 02:35:28 +03:00
|
|
|
std::ostream& operator<<(std::ostream& os, TreeEntryType type);
|
2017-07-05 21:17:03 +03:00
|
|
|
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2);
|
|
|
|
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2);
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|