mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
8e3c09a99a
Summary: Promote the folly logging code out of the experimental subdirectory. We have been using this for several months in a few projects and are pretty happy with it so far. After moving it out of the experimental/ subdirectory I plan to update folly::Init() to automatically support configuring it via a `--logging` command line flag (similar to the initialization it already does today for glog). Reviewed By: yfeldblum, chadaustin Differential Revision: D7755455 fbshipit-source-id: 052db34c97f7516728f7cbb1a5ad959def2f6efb
95 lines
2.5 KiB
C++
95 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2004-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.
|
|
*
|
|
*/
|
|
#include "eden/fs/model/TreeEntry.h"
|
|
|
|
#include <folly/Conv.h>
|
|
#include <folly/Range.h>
|
|
#include <folly/logging/xlog.h>
|
|
#include <sys/stat.h>
|
|
#include <ostream>
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
mode_t modeFromTreeEntryType(TreeEntryType ft) {
|
|
switch (ft) {
|
|
case TreeEntryType::TREE:
|
|
return S_IFDIR | 0755;
|
|
case TreeEntryType::REGULAR_FILE:
|
|
return S_IFREG | 0644;
|
|
case TreeEntryType::EXECUTABLE_FILE:
|
|
return S_IFREG | 0755;
|
|
case TreeEntryType::SYMLINK:
|
|
return S_IFLNK | 0755;
|
|
}
|
|
XLOG(FATAL) << "illegal file type " << static_cast<int>(ft);
|
|
}
|
|
|
|
folly::Optional<TreeEntryType> treeEntryTypeFromMode(mode_t mode) {
|
|
if (S_ISREG(mode)) {
|
|
return mode & S_IXUSR ? TreeEntryType::EXECUTABLE_FILE
|
|
: TreeEntryType::REGULAR_FILE;
|
|
} else if (S_ISLNK(mode)) {
|
|
return TreeEntryType::SYMLINK;
|
|
} else if (S_ISDIR(mode)) {
|
|
return TreeEntryType::TREE;
|
|
} else {
|
|
return folly::none;
|
|
}
|
|
}
|
|
|
|
std::string TreeEntry::toLogString() const {
|
|
char fileTypeChar = '?';
|
|
switch (type_) {
|
|
case TreeEntryType::TREE:
|
|
fileTypeChar = 'd';
|
|
break;
|
|
case TreeEntryType::REGULAR_FILE:
|
|
fileTypeChar = 'f';
|
|
break;
|
|
case TreeEntryType::EXECUTABLE_FILE:
|
|
fileTypeChar = 'x';
|
|
break;
|
|
case TreeEntryType::SYMLINK:
|
|
fileTypeChar = 'l';
|
|
break;
|
|
}
|
|
|
|
return folly::to<std::string>(
|
|
"(", name_, ", ", hash_.toString(), ", ", fileTypeChar, ")");
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, TreeEntryType type) {
|
|
switch (type) {
|
|
case TreeEntryType::TREE:
|
|
return os << "TREE";
|
|
case TreeEntryType::REGULAR_FILE:
|
|
return os << "REGULAR_FILE";
|
|
case TreeEntryType::EXECUTABLE_FILE:
|
|
return os << "EXECUTABLE_FILE";
|
|
case TreeEntryType::SYMLINK:
|
|
return os << "SYMLINK";
|
|
}
|
|
|
|
return os << "TreeEntryType::" << int(type);
|
|
}
|
|
|
|
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2) {
|
|
return (entry1.getHash() == entry2.getHash()) &&
|
|
(entry1.getType() == entry2.getType()) &&
|
|
(entry1.getName() == entry2.getName());
|
|
}
|
|
|
|
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2) {
|
|
return !(entry1 == entry2);
|
|
}
|
|
} // namespace eden
|
|
} // namespace facebook
|