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
|
|
|
|
|
|
|
|
#include "Hash.h"
|
|
|
|
#include "TreeEntry.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>
|
2018-02-16 01:23:07 +03:00
|
|
|
#include <folly/experimental/logging/xlog.h>
|
|
|
|
#include <sys/stat.h>
|
2017-03-17 23:21:33 +03:00
|
|
|
#include <iosfwd>
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
class Hash;
|
|
|
|
|
2018-02-16 01:23:07 +03:00
|
|
|
enum class TreeEntryType : uint8_t {
|
2016-05-12 23:43:17 +03:00
|
|
|
BLOB,
|
|
|
|
TREE,
|
|
|
|
};
|
|
|
|
|
2018-02-16 01:23:07 +03:00
|
|
|
enum class FileType : uint8_t {
|
|
|
|
DIRECTORY,
|
|
|
|
REGULAR_FILE,
|
|
|
|
EXECUTABLE_FILE,
|
|
|
|
SYMLINK,
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class TreeEntry {
|
|
|
|
public:
|
|
|
|
explicit TreeEntry(
|
|
|
|
const Hash& hash,
|
|
|
|
folly::StringPiece name,
|
2018-02-16 01:23:07 +03:00
|
|
|
FileType fileType)
|
|
|
|
: fileType_(fileType), hash_(hash), name_(PathComponentPiece(name)) {}
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
const Hash& getHash() const {
|
|
|
|
return hash_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathComponent& getName() const {
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeEntryType getType() const {
|
|
|
|
return fileType_ == FileType::DIRECTORY ? TreeEntryType::TREE
|
|
|
|
: TreeEntryType::BLOB;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileType getFileType() const {
|
|
|
|
return fileType_;
|
|
|
|
}
|
|
|
|
|
2016-10-19 20:53:00 +03:00
|
|
|
mode_t getMode() const {
|
2018-02-16 01:23:07 +03:00
|
|
|
switch (fileType_) {
|
|
|
|
case FileType::DIRECTORY:
|
|
|
|
return S_IFDIR | 0755;
|
|
|
|
case FileType::REGULAR_FILE:
|
|
|
|
return S_IFREG | 0644;
|
|
|
|
case FileType::EXECUTABLE_FILE:
|
|
|
|
return S_IFREG | 0755;
|
|
|
|
case FileType::SYMLINK:
|
|
|
|
return S_IFLNK | 0755;
|
|
|
|
}
|
|
|
|
XLOG(FATAL) << "illegal file type " << int(fileType_);
|
2016-12-21 03:23:22 +03:00
|
|
|
}
|
|
|
|
|
2017-10-26 02:49:58 +03:00
|
|
|
std::string toLogString() const;
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
private:
|
2016-07-07 23:35:39 +03:00
|
|
|
FileType fileType_;
|
|
|
|
Hash hash_;
|
|
|
|
PathComponent name_;
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
2017-03-17 23:21:33 +03:00
|
|
|
|
2018-02-16 01:23:07 +03:00
|
|
|
std::ostream& operator<<(std::ostream& os, FileType type);
|
2017-03-17 23:21:33 +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
|