This is an automated email from the ASF dual-hosted git repository.
amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new d66e724 Runroot: Change some dir keywords to const
d66e724 is described below
commit d66e724d2d76c72a61486ac057c878a71b0fd72c
Author: Xavier Chi <[email protected]>
AuthorDate: Mon Jun 25 13:46:13 2018 -0500
Runroot: Change some dir keywords to const
---
lib/ts/Layout.cc | 30 ++++++++++-----------
lib/ts/runroot.cc | 26 +++++++++---------
lib/ts/runroot.h | 17 ++++++++++++
src/traffic_layout/engine.cc | 55 ++++++++++++++++++++-------------------
src/traffic_layout/engine.h | 7 ++---
src/traffic_layout/file_system.cc | 19 +++++++-------
6 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/lib/ts/Layout.cc b/lib/ts/Layout.cc
index 4042e39..08fba29 100644
--- a/lib/ts/Layout.cc
+++ b/lib/ts/Layout.cc
@@ -120,21 +120,21 @@ Layout::Layout(std::string_view const _prefix)
int len;
RunrootMapType dir_map = check_runroot();
if (dir_map.size() != 0) {
- prefix = dir_map["prefix"];
- exec_prefix = dir_map["exec_prefix"];
- bindir = dir_map["bindir"];
- sbindir = dir_map["sbindir"];
- sysconfdir = dir_map["sysconfdir"];
- datadir = dir_map["datadir"];
- includedir = dir_map["includedir"];
- libdir = dir_map["libdir"];
- libexecdir = dir_map["libexecdir"];
- localstatedir = dir_map["localstatedir"];
- runtimedir = dir_map["runtimedir"];
- logdir = dir_map["logdir"];
- mandir = dir_map["mandir"];
- infodir = dir_map["infodir"];
- cachedir = dir_map["cachedir"];
+ prefix = dir_map[LAYOUT_PREFIX];
+ exec_prefix = dir_map[LAYOUT_EXEC_PREFIX];
+ bindir = dir_map[LAYOUT_BINDIR];
+ sbindir = dir_map[LAYOUT_SBINDIR];
+ sysconfdir = dir_map[LAYOUT_SYSCONFDIR];
+ datadir = dir_map[LAYOUT_DATADIR];
+ includedir = dir_map[LAYOUT_INCLUDEDIR];
+ libdir = dir_map[LAYOUT_LIBDIR];
+ libexecdir = dir_map[LAYOUT_LIBEXECDIR];
+ localstatedir = dir_map[LAYOUT_LOCALSTATEDIR];
+ runtimedir = dir_map[LAYOUT_RUNTIMEDIR];
+ logdir = dir_map[LAYOUT_LOGDIR];
+ mandir = dir_map[LAYOUT_MANDIR];
+ infodir = dir_map[LAYOUT_INFODIR];
+ cachedir = dir_map[LAYOUT_CACHEDIR];
return;
}
if (getenv("TS_ROOT") != nullptr) {
diff --git a/lib/ts/runroot.cc b/lib/ts/runroot.cc
index 23e103a..9624b08 100644
--- a/lib/ts/runroot.cc
+++ b/lib/ts/runroot.cc
@@ -188,20 +188,20 @@ runroot_map_default()
{
std::unordered_map<std::string, std::string> map;
- map["prefix"] = Layout::get()->prefix;
- map["exec_prefix"] = Layout::get()->exec_prefix;
- map["bindir"] = Layout::get()->bindir;
- map["sbindir"] = Layout::get()->sbindir;
- map["sysconfdir"] = Layout::get()->sysconfdir;
- map["datadir"] = Layout::get()->datadir;
- map["includedir"] = Layout::get()->includedir;
- map["libdir"] = Layout::get()->libdir;
- map["libexecdir"] = Layout::get()->libexecdir;
- map["localstatedir"] = Layout::get()->localstatedir;
- map["runtimedir"] = Layout::get()->runtimedir;
- map["logdir"] = Layout::get()->logdir;
+ map[LAYOUT_PREFIX] = Layout::get()->prefix;
+ map[LAYOUT_EXEC_PREFIX] = Layout::get()->exec_prefix;
+ map[LAYOUT_BINDIR] = Layout::get()->bindir;
+ map[LAYOUT_SBINDIR] = Layout::get()->sbindir;
+ map[LAYOUT_SYSCONFDIR] = Layout::get()->sysconfdir;
+ map[LAYOUT_DATADIR] = Layout::get()->datadir;
+ map[LAYOUT_INCLUDEDIR] = Layout::get()->includedir;
+ map[LAYOUT_LIBDIR] = Layout::get()->libdir;
+ map[LAYOUT_LIBEXECDIR] = Layout::get()->libexecdir;
+ map[LAYOUT_LOCALSTATEDIR] = Layout::get()->localstatedir;
+ map[LAYOUT_RUNTIMEDIR] = Layout::get()->runtimedir;
+ map[LAYOUT_LOGDIR] = Layout::get()->logdir;
// mandir is not needed for runroot
- map["cachedir"] = Layout::get()->cachedir;
+ map[LAYOUT_CACHEDIR] = Layout::get()->cachedir;
return map;
}
diff --git a/lib/ts/runroot.h b/lib/ts/runroot.h
index 96ba791..4256cfc 100644
--- a/lib/ts/runroot.h
+++ b/lib/ts/runroot.h
@@ -29,6 +29,23 @@
#include <string>
#include <unordered_map>
+// name of the directory declared globally
+const std::string LAYOUT_PREFIX = "prefix";
+const std::string LAYOUT_EXEC_PREFIX = "exec_prefix";
+const std::string LAYOUT_BINDIR = "bindir";
+const std::string LAYOUT_SBINDIR = "sbindir";
+const std::string LAYOUT_SYSCONFDIR = "sysconfdir";
+const std::string LAYOUT_DATADIR = "datadir";
+const std::string LAYOUT_INCLUDEDIR = "includedir";
+const std::string LAYOUT_LIBDIR = "libdir";
+const std::string LAYOUT_LIBEXECDIR = "libexecdir";
+const std::string LAYOUT_LOCALSTATEDIR = "localstatedir";
+const std::string LAYOUT_RUNTIMEDIR = "runtimedir";
+const std::string LAYOUT_LOGDIR = "logdir";
+const std::string LAYOUT_MANDIR = "mandir";
+const std::string LAYOUT_INFODIR = "infodir";
+const std::string LAYOUT_CACHEDIR = "cachedir";
+
typedef std::unordered_map<std::string, std::string> RunrootMapType;
std::string check_path(const std::string &path);
diff --git a/src/traffic_layout/engine.cc b/src/traffic_layout/engine.cc
index 6055ac8..1d95d46 100644
--- a/src/traffic_layout/engine.cc
+++ b/src/traffic_layout/engine.cc
@@ -259,7 +259,7 @@ RunrootEngine::sanity_check()
if (path.empty()) {
if (!verify_flag) {
- ink_fatal("Path not valild (runroot_path.yml not found)");
+ ink_fatal("Path not valid (runroot_path.yml not found)");
} else {
verify_default = true;
}
@@ -317,8 +317,8 @@ RunrootEngine::clean_runroot()
} else {
// handle the map and deleting of each directories specified in the yml
file
RunrootMapType map = runroot_map(clean_root);
- map.erase("prefix");
- map.erase("exec_prefix");
+ map.erase(LAYOUT_PREFIX);
+ map.erase(LAYOUT_EXEC_PREFIX);
for (auto it : map) {
std::string dir = it.second;
append_slash(dir);
@@ -421,20 +421,20 @@ RunrootEngine::copy_runroot(const std::string
&original_root, const std::string
// map the original build time directory
RunrootMapType original_map;
- original_map["exec_prefix"] = TS_BUILD_EXEC_PREFIX;
- original_map["bindir"] = TS_BUILD_BINDIR;
- original_map["sbindir"] = TS_BUILD_SBINDIR;
- original_map["sysconfdir"] = TS_BUILD_SYSCONFDIR;
- original_map["datadir"] = TS_BUILD_DATADIR;
- original_map["includedir"] = TS_BUILD_INCLUDEDIR;
- original_map["libdir"] = TS_BUILD_LIBDIR;
- original_map["libexecdir"] = TS_BUILD_LIBEXECDIR;
- original_map["localstatedir"] = TS_BUILD_LOCALSTATEDIR;
- original_map["runtimedir"] = TS_BUILD_RUNTIMEDIR;
- original_map["logdir"] = TS_BUILD_LOGDIR;
- original_map["mandir"] = TS_BUILD_MANDIR;
- original_map["infodir"] = TS_BUILD_INFODIR;
- original_map["cachedir"] = TS_BUILD_CACHEDIR;
+ original_map[LAYOUT_EXEC_PREFIX] = TS_BUILD_EXEC_PREFIX;
+ original_map[LAYOUT_BINDIR] = TS_BUILD_BINDIR;
+ original_map[LAYOUT_SBINDIR] = TS_BUILD_SBINDIR;
+ original_map[LAYOUT_SYSCONFDIR] = TS_BUILD_SYSCONFDIR;
+ original_map[LAYOUT_DATADIR] = TS_BUILD_DATADIR;
+ original_map[LAYOUT_INCLUDEDIR] = TS_BUILD_INCLUDEDIR;
+ original_map[LAYOUT_LIBDIR] = TS_BUILD_LIBDIR;
+ original_map[LAYOUT_LIBEXECDIR] = TS_BUILD_LIBEXECDIR;
+ original_map[LAYOUT_LOCALSTATEDIR] = TS_BUILD_LOCALSTATEDIR;
+ original_map[LAYOUT_RUNTIMEDIR] = TS_BUILD_RUNTIMEDIR;
+ original_map[LAYOUT_LOGDIR] = TS_BUILD_LOGDIR;
+ original_map[LAYOUT_MANDIR] = TS_BUILD_MANDIR;
+ original_map[LAYOUT_INFODIR] = TS_BUILD_INFODIR;
+ original_map[LAYOUT_CACHEDIR] = TS_BUILD_CACHEDIR;
// copy each directory to the runroot path
// symlink the executables
@@ -457,7 +457,8 @@ RunrootEngine::copy_runroot(const std::string
&original_root, const std::string
}
// don't copy the prefix, mandir, localstatedir and infodir
- if (it.first != "exec_prefix" && it.first != "localstatedir" && it.first
!= "mandir" && it.first != "infodir") {
+ if (it.first != LAYOUT_EXEC_PREFIX && it.first != LAYOUT_LOCALSTATEDIR &&
it.first != LAYOUT_MANDIR &&
+ it.first != LAYOUT_INFODIR) {
if (!copy_directory(old_path, new_path, it.first)) {
ink_warning("Unable to copy '%s' - %s", it.first.c_str(),
strerror(errno));
ink_notice("Creating '%s': %s", it.first.c_str(), new_path.c_str());
@@ -472,9 +473,9 @@ RunrootEngine::copy_runroot(const std::string
&original_root, const std::string
std::cout << "Copying from " + original_root + " ..." << std::endl;
if (abs_flag) {
- path_map["prefix"] = ts_runroot;
+ path_map[LAYOUT_PREFIX] = ts_runroot;
} else {
- path_map["prefix"] = ".";
+ path_map[LAYOUT_PREFIX] = ".";
}
}
@@ -575,7 +576,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType
&permission_map, RunrootMap
}
std::cout << "Read permission fixed for '" + name + "': " + path <<
std::endl;
}
- if (name == "logdir" || name == "runtimedir" || name == "cachedir") {
+ if (name == LAYOUT_LOGDIR || name == LAYOUT_RUNTIMEDIR || name ==
LAYOUT_CACHEDIR) {
// write
if (permission[1] != '1') {
if (chmod(path.c_str(), stat_buffer.st_mode | read_permission |
write_permission) < 0) {
@@ -584,7 +585,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType
&permission_map, RunrootMap
std::cout << "Write permission fixed for '" + name + "': " + path <<
std::endl;
}
}
- if (name == "bindir" || name == "sbindir" || name == "libdir" || name ==
"libexecdir") {
+ if (name == LAYOUT_BINDIR || name == LAYOUT_SBINDIR || name ==
LAYOUT_LIBDIR || name == LAYOUT_LIBEXECDIR) {
// execute
if (permission[2] != '1') {
if (chmod(path.c_str(), stat_buffer.st_mode | read_permission |
execute_permission) < 0) {
@@ -598,7 +599,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType
&permission_map, RunrootMap
// set permission to the map in verify runroot
static void
-set_permission(std::vector<std::string> &dir_vector, RunrootMapType &path_map,
RunrootMapType &permission_map,
+set_permission(std::vector<std::string> const &dir_vector, RunrootMapType
&path_map, RunrootMapType &permission_map,
RunrootMapType &usergroup_map)
{
// active group and user of the path
@@ -614,7 +615,7 @@ set_permission(std::vector<std::string> &dir_vector,
RunrootMapType &path_map, R
std::string name = dir_vector[i];
std::string value = path_map[name];
- if (name == "prefix" || name == "exec_prefix") {
+ if (name == LAYOUT_PREFIX || name == LAYOUT_EXEC_PREFIX) {
continue;
}
@@ -698,16 +699,16 @@ RunrootEngine::verify_runroot()
std::cout << name << ": \x1b[1m" + path_map[name] + "\x1b[0m" << std::endl;
// output read permission
- if (name == "localstatedir" || name == "includedir" || name ==
"sysconfdir" || name == "datadir") {
+ if (name == LAYOUT_LOCALSTATEDIR || name == LAYOUT_INCLUDEDIR || name ==
LAYOUT_SYSCONFDIR || name == LAYOUT_DATADIR) {
output_read_permission(permission);
}
// output write permission
- if (name == "logdir" || name == "runtimedir" || name == "cachedir") {
+ if (name == LAYOUT_LOGDIR || name == LAYOUT_RUNTIMEDIR || name ==
LAYOUT_CACHEDIR) {
output_read_permission(permission);
output_write_permission(permission);
}
// output execute permission
- if (name == "bindir" || name == "sbindir" || name == "libdir" || name ==
"libexecdir") {
+ if (name == LAYOUT_BINDIR || name == LAYOUT_SBINDIR || name ==
LAYOUT_LIBDIR || name == LAYOUT_LIBEXECDIR) {
output_read_permission(permission);
output_execute_permission(permission);
}
diff --git a/src/traffic_layout/engine.h b/src/traffic_layout/engine.h
index 7144ac4..82c7581 100644
--- a/src/traffic_layout/engine.h
+++ b/src/traffic_layout/engine.h
@@ -75,9 +75,10 @@ struct RunrootEngine {
std::string path;
// vector containing all directory names
- std::vector<std::string> dir_vector = {"prefix", "exec_prefix",
"bindir", "sbindir", "sysconfdir",
- "datadir", "includedir",
"libdir", "libexecdir", "localstatedir",
- "runtimedir", "logdir",
"cachedir"};
+ std::vector<std::string> const dir_vector = {LAYOUT_PREFIX,
LAYOUT_EXEC_PREFIX, LAYOUT_BINDIR, LAYOUT_SBINDIR,
+ LAYOUT_SYSCONFDIR,
LAYOUT_DATADIR, LAYOUT_INCLUDEDIR, LAYOUT_LIBDIR,
+ LAYOUT_LIBEXECDIR,
LAYOUT_LOCALSTATEDIR, LAYOUT_RUNTIMEDIR, LAYOUT_LOGDIR,
+ LAYOUT_CACHEDIR};
// map for yaml file emit
RunrootMapType path_map;
diff --git a/src/traffic_layout/file_system.cc
b/src/traffic_layout/file_system.cc
index 7706a25..e7bca3a 100644
--- a/src/traffic_layout/file_system.cc
+++ b/src/traffic_layout/file_system.cc
@@ -27,6 +27,7 @@
#include "ts/ink_error.h"
#include "ts/I_Layout.h"
+#include "ts/runroot.h"
#include "file_system.h"
#include <iostream>
@@ -44,9 +45,9 @@ static std::string copy_dir; // the current dir we are
copying. e.x. sysconfdir,
static std::string remove_path;
// list of all executables of traffic server
-std::set<std::string> executables = {"traffic_crashlog", "traffic_ctl",
"traffic_layout", "traffic_logcat",
- "traffic_logstats", "traffic_manager",
"traffic_server", "traffic_top",
- "traffic_via", "trafficserver",
"tspush", "tsxs"};
+std::set<std::string> const executables = {"traffic_crashlog", "traffic_ctl",
"traffic_layout", "traffic_logcat",
+ "traffic_logstats",
"traffic_manager", "traffic_server", "traffic_top",
+ "traffic_via",
"trafficserver", "tspush", "tsxs"};
void
append_slash(std::string &path)
@@ -200,17 +201,17 @@ ts_copy_function(const char *src_path, const struct stat
*sb, int flag)
// copying a directory
case FTW_D:
// ----- filter traffic server related files -----
- if (copy_dir == "bindir" || copy_dir == "sbindir") {
+ if (copy_dir == LAYOUT_BINDIR || copy_dir == LAYOUT_SBINDIR) {
// no directory from bindir and sbindir should be copied.
break;
}
- if (copy_dir == "libdir") {
+ if (copy_dir == LAYOUT_LIBDIR) {
// valid directory of libdir are perl5 and pkgconfig. If not one of
those, end the copying.
if (dst_path.find("/perl5") == std::string::npos &&
dst_path.find("/pkgconfig") == std::string::npos) {
break;
}
}
- if (copy_dir == "includedir") {
+ if (copy_dir == LAYOUT_INCLUDEDIR) {
// valid directory of includedir are atscppapi and ts. If not one of
those, end the copying.
if (dst_path.find("/atscppapi") == std::string::npos &&
dst_path.find("/ts") == std::string::npos) {
break;
@@ -225,13 +226,13 @@ ts_copy_function(const char *src_path, const struct stat
*sb, int flag)
// copying a file
case FTW_F:
// ----- filter traffic server related files -----
- if (copy_dir == "bindir" || copy_dir == "sbindir") {
+ if (copy_dir == LAYOUT_BINDIR || copy_dir == LAYOUT_SBINDIR) {
// check if executable is in the list of traffic server executables. If
not, end the copying.
if (executables.find(dst_path.substr(dst_path.find_last_of("/") + 1)) ==
executables.end()) {
break;
}
}
- if (copy_dir == "libdir") {
+ if (copy_dir == LAYOUT_LIBDIR) {
// check if library file starts with libats, libts or contained in
perl5/ and pkgconfig/.
// If not, end the copying.
if (dst_path.find("/perl5/") == std::string::npos &&
dst_path.find("/pkgconfig/") == std::string::npos &&
@@ -239,7 +240,7 @@ ts_copy_function(const char *src_path, const struct stat
*sb, int flag)
break;
}
}
- if (copy_dir == "includedir") {
+ if (copy_dir == LAYOUT_INCLUDEDIR) {
// check if include file is contained in atscppapi/ and ts/. If not, end
the copying.
if (dst_path.find("/atscppapi/") == std::string::npos &&
dst_path.find("/ts/") == std::string::npos) {
break;