bdbf09afe8d2cd07513a908431a50e641cecc28d
Stefan Schuermans add copyright & license

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp  1) /**
libpermissioner/src/Config.cpp  2)  * Permissioner: set file ownerships and permissions
libpermissioner/src/Config.cpp  3)  * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
libpermissioner/src/Config.cpp  4)  * Copyleft: GNU GENERAL PUBLIC LICENSE version 3 (see LICENSE)
libpermissioner/src/Config.cpp  5)  */
libpermissioner/src/Config.cpp  6) 
Stefan Schuermans move most sources into libp...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp  7) #include <permissioner/Config.h>
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Config.cpp    8) 
Stefan Schuermans fix long shutdown delay aft...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp  9) #include <permissioner/Callback.h>
libpermissioner/src/Config.cpp 10) #include <permissioner/StringUtils.h>
Stefan Schuermans move most sources into libp...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 11) #include <permissioner/Tree.h>
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Config.cpp   12) 
permissionerd/src/Config.cpp   13) #include <boost/filesystem.hpp>
permissionerd/src/Config.cpp   14) #include <fstream>
permissionerd/src/Config.cpp   15) #include <map>
permissionerd/src/Config.cpp   16) #include <sstream>
permissionerd/src/Config.cpp   17) #include <stdexcept>
permissionerd/src/Config.cpp   18) #include <string>
permissionerd/src/Config.cpp   19) 
permissionerd/src/Config.cpp   20) void Config::parseFile(std::string const &configFileName) {
permissionerd/src/Config.cpp   21)   std::ifstream configFile(configFileName, std::ios::in);
permissionerd/src/Config.cpp   22)   if (! configFile.is_open()) {
permissionerd/src/Config.cpp   23)     std::stringstream msg;
permissionerd/src/Config.cpp   24)     msg << "cannot open file \"" << configFileName << "\" for reading";
permissionerd/src/Config.cpp   25)     throw std::runtime_error(msg.str());
permissionerd/src/Config.cpp   26)   }
permissionerd/src/Config.cpp   27) 
permissionerd/src/Config.cpp   28)   for (std::string line; std::getline(configFile, line); ) {
permissionerd/src/Config.cpp   29)     std::string::size_type pos = 0;
permissionerd/src/Config.cpp   30)     std::string typeStr;
permissionerd/src/Config.cpp   31)     try {
permissionerd/src/Config.cpp   32)       StringUtils::getNextField(line, pos, typeStr, "config line type");
permissionerd/src/Config.cpp   33)     } catch (std::exception const &e) {
permissionerd/src/Config.cpp   34)       continue; // empty line -> ignore
permissionerd/src/Config.cpp   35)     }
permissionerd/src/Config.cpp   36)     if (typeStr == "#") {
permissionerd/src/Config.cpp   37)       continue; // comment line -> ignore
permissionerd/src/Config.cpp   38)     }
Stefan Schuermans canonicalize root paths

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 39)     // actual configuration lines
Stefan Schuermans add nice and I/O idle config

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 40)     if (typeStr == "nice") {
libpermissioner/src/Config.cpp 41)       nice.parseParams(line.substr(pos));
libpermissioner/src/Config.cpp 42)       continue;
libpermissioner/src/Config.cpp 43)     }
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Config.cpp   44)     if (typeStr == "tree") {
permissionerd/src/Config.cpp   45)       Tree tree;
permissionerd/src/Config.cpp   46)       tree.parseParams(line.substr(pos));
Stefan Schuermans add config getters

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 47)       trees[tree.getRoot()] = tree;
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Config.cpp   48)       continue;
permissionerd/src/Config.cpp   49)     }
permissionerd/src/Config.cpp   50)     // unknown configuration line
permissionerd/src/Config.cpp   51)     std::stringstream msg;
permissionerd/src/Config.cpp   52)     msg << "unknown configuration type \"" << typeStr << "\"";
permissionerd/src/Config.cpp   53)     throw std::runtime_error(msg.str());
permissionerd/src/Config.cpp   54)   }
permissionerd/src/Config.cpp   55) }
Stefan Schuermans add config getters

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 56) 
Stefan Schuermans add nice and I/O idle config

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 57) Nice const & Config::getNice() const {
libpermissioner/src/Config.cpp 58)   return nice;
libpermissioner/src/Config.cpp 59) }
libpermissioner/src/Config.cpp 60) 
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 61) TreeMap const & Config::getTrees() const {
Stefan Schuermans add config getters

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 62)   return trees;
libpermissioner/src/Config.cpp 63) }
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 64) 
Stefan Schuermans fix long shutdown delay aft...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 65) bool Config::setPermissions(Callback &callback) const {
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 66)   for (auto const & path_tree : trees) {
libpermissioner/src/Config.cpp 67)     Tree const & tree = path_tree.second;
Stefan Schuermans fix long shutdown delay aft...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 68)     if (! tree.setPermissions(trees, callback)) { // exclude all other trees
libpermissioner/src/Config.cpp 69)       return false;
libpermissioner/src/Config.cpp 70)     }
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 71)   }
Stefan Schuermans fix long shutdown delay aft...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Config.cpp 72)   return true;