sapling/eden/integration/fsattr.cpp
Wez Furlong d6adcfc058 add fsattr utility for testing purposes
Summary:
This is the spiritual successor to D3302706 which originally
wanted to solve this by adding a python extension.  That would prove
to be too painful for the opensource build so it was shelved.

We now need to be able to run our tests in an environment that doesn't
have the `attr` rpm installed so this is a good time to fix this
in a more portable way.

This diff adds a little wrapper around the functions that we already
have for consuming extended attribute information and augments them
with another to list attributes.

The utility emits output in json format and is intended to be fed
directly into the helper functions we have in `fs.py`.

Reviewed By: chadaustin

Differential Revision: D6851182

fbshipit-source-id: 3d1d1a351f2e01405645d45658d1c8bc61a659a4
2018-01-30 21:50:39 -08:00

49 lines
1.2 KiB
C++

/*
* Copyright (c) 2018-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 <folly/dynamic.h>
#include <folly/init/Init.h>
#include <folly/json.h>
#include <gflags/gflags.h>
#include "eden/fs/utils/XAttr.h"
DEFINE_string(fileName, "", "the path to examine");
DEFINE_string(
attrName,
"",
"the name of the attribute to return, else list all of them");
int main(int argc, char** argv) {
folly::init(&argc, &argv);
folly::dynamic result;
if (FLAGS_attrName.empty()) {
// List attributes
result = folly::dynamic::object();
for (auto& name : facebook::eden::listxattr(FLAGS_fileName)) {
auto value = facebook::eden::getxattr(FLAGS_fileName, name);
result.insert(name, value);
}
} else {
// Return named attribute
result = facebook::eden::getxattr(FLAGS_fileName, FLAGS_attrName);
}
auto serialized =
folly::json::serialize(result, folly::json::serialization_opts());
fwrite(serialized.data(), 1, serialized.size(), stdout);
puts("\n");
return 0;
}