8 #include <forward_list>
34 acls.acl_type = GPFS_ACL_TYPE_ACCESS;
38 static const std::string pattern(
"/.aclgetXXXXXX");
39 std::vector<char> tmpName;
40 tmpName.reserve(
path.size() + pattern.size());
41 tmpName.insert(tmpName.end(),
path.cbegin(),
path.cend());
42 tmpName.insert(tmpName.end(), pattern.cbegin(), pattern.cend());
43 tmpName.push_back(
'\0');
45 throwcall::badval(mkdtemp(tmpName.data()),
nullptr,
"can't create tmp dir '", tmpName.data(),
"'");
47 auto fd =
throwcall::badval(mkstemp(tmpName.data()), -1,
"can't create tmp file '", tmpName.data(),
"'");
50 throwcall::good0(gpfs_getacl(tmpName.data(), 0, &
acls),
"can't get acl for '", tmpName.data(),
"'");
52 throwcall::good0(rmdir(tmpName.data()),
"can't remove '", tmpName.data(),
"'");
54 throwcall::good0(unlink(tmpName.data()),
"can't remove '", tmpName.data(),
"'");
67 std::forward_list<std::string> subdirs;
71 while (
auto entry = readdir(dir)) {
72 if (entry->d_name[entry->d_name[0] !=
'.' ? 0 : entry->d_name[1] !=
'.' ? 1 : 2] ==
'\0') {
76 throwcall::good0(fstatat(dirfd(dir), entry->d_name, &statbuf, AT_SYMLINK_NOFOLLOW),
"can't stat '", entry->d_name,
"' in '", path,
"'");
77 if (S_ISDIR(statbuf.st_mode)) {
78 subdirs.emplace_front(path +
"/" + entry->d_name);
79 }
else if (S_ISREG(statbuf.st_mode)) {
80 std::string filePath(path);
82 filePath += entry->d_name;
84 throwcall::good0(gpfs_putacl(filePath.c_str(), 0, fileAcls),
"can't set acl for '", filePath,
"'");
86 std::cerr <<
"ignoring '" << entry->d_name <<
"' in '" << path <<
"', it's neither dir nor file\n";
90 if (!subdirs.empty()) {
92 for (
const auto& subdir : subdirs) {
94 throwcall::good0(gpfs_putacl(subdir.c_str(), 0, dirAcls),
"can't set acl for '", subdir,
"'");
97 for (
const auto& subdir : subdirs) {
103 int main(
int argc,
const char *argv[]) {
105 "set the ACLs of the files given on the command line\n"
106 "\t to those they would inherit from theirparent directories.\n"
107 "\tDirectories given on the command line are left unchanged,\n"
108 "\t but all their content is recursively scanned and the ACLs\n"
109 "\t of all their sub-directories and files are set\n"
110 "\t as if freshly inherited.\n"
113 "files to be fixed");
114 parser.fParse(argc, argv);
115 std::map<std::string, aclBuffer> fileAcls;
116 for (
const auto& file : files) {
119 if (S_ISDIR(statbuf.st_mode)) {
121 }
else if (S_ISREG(statbuf.st_mode)) {
122 auto lastSlash = file.find_last_of(
'/');
123 auto dirPath = lastSlash == std::string::npos ?
"." : file.substr(0, lastSlash);
124 auto bla = fileAcls.emplace(dirPath, dirPath);
126 throwcall::good0(gpfs_putacl(file.c_str(), 0, bla.first->second),
"can't set acl for '", file,
"'");
128 std::cerr <<
"ignoring '" << file <<
"', it's neither dir nor file\n";
131 std::cout <<
"processed " <<
nFiles <<
" files in " <<
nDirs <<
" directories\n";