ewmscp  ..
Functions | Variables
The fixGpfsAcls command

This tool sets the ACLs of the files given on the command line to those they would inherit from theirparent directories. Directories given on the command line are left unchanged, but all their content is recursively scanned and the ACLs of all their sub-directories and files are set as if freshly inherited. More...

Functions

void handleDir (const std::string &path)
 
int main (int argc, const char *argv[])
 

Variables

static unsigned long nDirs = 0
 
static unsigned long nFiles = 0
 

Detailed Description

This tool sets the ACLs of the files given on the command line to those they would inherit from theirparent directories. Directories given on the command line are left unchanged, but all their content is recursively scanned and the ACLs of all their sub-directories and files are set as if freshly inherited.

Function Documentation

◆ handleDir()

void handleDir ( const std::string &  path)

Definition at line 66 of file fixGpfsAcls.cpp.

66  {
67  std::forward_list<std::string> subdirs;
68  {
69  scoped::Dir dir(path);
70  aclBuffer fileAcls(path);
71  while (auto entry = readdir(dir)) {
72  if (entry->d_name[entry->d_name[0] != '.' ? 0 : entry->d_name[1] != '.' ? 1 : 2] == '\0') {
73  continue; // skip . .. and empty strings
74  }
75  struct stat statbuf;
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);
81  filePath += "/";
82  filePath += entry->d_name;
83  nFiles++;
84  throwcall::good0(gpfs_putacl(filePath.c_str(), 0, fileAcls), "can't set acl for '", filePath, "'");
85  } else {
86  std::cerr << "ignoring '" << entry->d_name << "' in '" << path << "', it's neither dir nor file\n";
87  }
88  }
89  }
90  if (!subdirs.empty()) {
91  aclBuffer dirAcls(path, true);
92  for (const auto& subdir : subdirs) {
93  nDirs++;
94  throwcall::good0(gpfs_putacl(subdir.c_str(), 0, dirAcls), "can't set acl for '", subdir, "'");
95  }
96  }
97  for (const auto& subdir : subdirs) {
98  handleDir(subdir);
99  }
100 }

References throwcall::good0(), nDirs, and nFiles.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 103 of file fixGpfsAcls.cpp.

103  {
104  options::parser parser(
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"
111  , "", {});
113  "files to be fixed");
114  parser.fParse(argc, argv);
115  std::map<std::string, aclBuffer> fileAcls;
116  for (const auto& file : files) {
117  struct stat statbuf;
118  throwcall::good0(lstat(file.c_str(), &statbuf), "can't stat ", file);
119  if (S_ISDIR(statbuf.st_mode)) {
120  handleDir(file);
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);
125  nFiles++;
126  throwcall::good0(gpfs_putacl(file.c_str(), 0, bla.first->second), "can't set acl for '", file, "'");
127  } else {
128  std::cerr << "ignoring '" << file << "', it's neither dir nor file\n";
129  }
130  }
131  std::cout << "processed " << nFiles << " files in " << nDirs << " directories\n";
132  return 0;
133 }

References throwcall::good0(), handleDir(), nDirs, and nFiles.

Here is the call graph for this function:

Variable Documentation

◆ nDirs

unsigned long nDirs = 0
static

Definition at line 62 of file fixGpfsAcls.cpp.

Referenced by handleDir(), and main().

◆ nFiles

unsigned long nFiles = 0
static

Definition at line 63 of file fixGpfsAcls.cpp.

Referenced by handleDir(), and main().

options::parser
class that contains the parser, i.e. does that option handling
Definition: Options.h:363
aclBuffer
Definition: fixGpfsAcls.cpp:24
handleDir
void handleDir(const std::string &path)
Definition: fixGpfsAcls.cpp:66
nFiles
static unsigned long nFiles
Definition: fixGpfsAcls.cpp:63
nDirs
static unsigned long nDirs
Definition: fixGpfsAcls.cpp:62
scoped::Dir
Definition: scoped.h:71
options::positional
Definition: Options.h:876
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40