Replaced os::dirname and os::basename with Path::dirname and Path::basename.
Review: https://reviews.apache.org/r/34260 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/505d3838 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/505d3838 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/505d3838 Branch: refs/heads/master Commit: 505d3838d01eca2042dfb0dabe62b120b596cb7e Parents: e2988c4 Author: Till Toenshoff <[email protected]> Authored: Wed Jun 24 19:52:32 2015 +0200 Committer: Till Toenshoff <[email protected]> Committed: Wed Jun 24 19:52:35 2015 +0200 ---------------------------------------------------------------------- src/cli/mesos.cpp | 25 ++++++++------------ src/cli/resolve.cpp | 4 ++-- src/examples/balloon_framework.cpp | 5 +++- src/examples/long_lived_framework.cpp | 6 +++-- src/examples/low_level_scheduler_libprocess.cpp | 9 ++++--- src/examples/low_level_scheduler_pthread.cpp | 8 +++++-- src/examples/persistent_volume_framework.cpp | 3 ++- src/examples/test_framework.cpp | 7 ++++-- src/files/files.cpp | 12 ++++------ src/health-check/main.cpp | 3 ++- src/launcher/executor.cpp | 6 +++-- src/linux/cgroups.cpp | 9 ++----- src/local/main.cpp | 3 ++- src/logging/logging.cpp | 10 ++------ src/slave/containerizer/fetcher.cpp | 2 +- .../isolators/cgroups/cpushare.cpp | 3 ++- .../containerizer/isolators/cgroups/mem.cpp | 3 ++- .../isolators/cgroups/perf_event.cpp | 3 ++- .../isolators/network/port_mapping.cpp | 15 ++++-------- src/slave/containerizer/linux_launcher.cpp | 5 ++-- src/slave/state.cpp | 15 ++++++------ src/slave/state.hpp | 13 ++++------ src/slave/status_update_manager.cpp | 5 ++-- src/tests/fetcher_tests.cpp | 13 ++++------ src/tests/mesos.cpp | 2 +- src/zookeeper/group.cpp | 9 +++---- 26 files changed, 94 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/cli/mesos.cpp ---------------------------------------------------------------------- diff --git a/src/cli/mesos.cpp b/src/cli/mesos.cpp index bb92b68..0c315f7 100644 --- a/src/cli/mesos.cpp +++ b/src/cli/mesos.cpp @@ -30,10 +30,8 @@ void usage(const char* argv0) foreach (const string& match, matches.get()) { Try<bool> access = os::access(match, X_OK); if (access.isSome() && access.get()) { - Try<string> basename = os::basename(match); - if (basename.isSome()) { - commands.push_back(basename.get().substr(6)); - } + string basename = Path(match).basename(); + commands.push_back(basename.substr(6)); } } } @@ -41,7 +39,7 @@ void usage(const char* argv0) } cerr - << "Usage: " << os::basename(argv0).get() << " <command> [OPTIONS]" + << "Usage: " << Path(argv0).basename() << " <command> [OPTIONS]" << endl << endl << "Available commands:" << endl @@ -60,16 +58,13 @@ int main(int argc, char** argv) // Try and add the absolute dirname of argv[0] to PATH so we can // find commands (since our installation directory might not be on // the path). - Try<string> dirname = os::dirname(argv[0]); - if (dirname.isSome()) { - Result<string> realpath = os::realpath(dirname.get()); - if (realpath.isSome()) { - value = os::getenv("PATH"); - if (value.isSome()) { - os::setenv("PATH", realpath.get() + ":" + value.get()); - } else { - os::setenv("PATH", realpath.get()); - } + Result<string> realpath = os::realpath(Path(argv[0]).dirname()); + if (realpath.isSome()) { + value = os::getenv("PATH"); + if (value.isSome()) { + os::setenv("PATH", realpath.get() + ":" + value.get()); + } else { + os::setenv("PATH", realpath.get()); } } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/cli/resolve.cpp ---------------------------------------------------------------------- diff --git a/src/cli/resolve.cpp b/src/cli/resolve.cpp index 74545a0..dcb1d37 100644 --- a/src/cli/resolve.cpp +++ b/src/cli/resolve.cpp @@ -24,7 +24,7 @@ #include <stout/flags.hpp> #include <stout/none.hpp> #include <stout/nothing.hpp> -#include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/strings.hpp> #include <stout/try.hpp> @@ -46,7 +46,7 @@ using std::string; int main(int argc, char** argv) { flags::FlagsBase flags; - flags.setUsageMessage("Usage: " + os::basename(argv[0]).get() + " <master>"); + flags.setUsageMessage("Usage: " + Path(argv[0]).basename() + " <master>"); Duration timeout; flags.add(&timeout, http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/balloon_framework.cpp ---------------------------------------------------------------------- diff --git a/src/examples/balloon_framework.cpp b/src/examples/balloon_framework.cpp index 1eb5945..dfffffa 100644 --- a/src/examples/balloon_framework.cpp +++ b/src/examples/balloon_framework.cpp @@ -31,6 +31,7 @@ #include <stout/numify.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include "common/protobuf_utils.hpp" @@ -206,7 +207,9 @@ int main(int argc, char** argv) if (value.isSome()) { uri = path::join(value.get(), "src", "balloon-executor"); } else { - uri = path::join(os::realpath(dirname(argv[0])).get(), "balloon-executor"); + uri = path::join( + os::realpath(Path(argv[0]).dirname()).get(), + "balloon-executor"); } ExecutorInfo executor; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/long_lived_framework.cpp ---------------------------------------------------------------------- diff --git a/src/examples/long_lived_framework.cpp b/src/examples/long_lived_framework.cpp index 3f2ebe0..2e91e6b 100644 --- a/src/examples/long_lived_framework.cpp +++ b/src/examples/long_lived_framework.cpp @@ -28,6 +28,7 @@ #include <stout/numify.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> using namespace mesos; @@ -167,8 +168,9 @@ int main(int argc, char** argv) if (value.isSome()) { uri = path::join(value.get(), "src", "long-lived-executor"); } else { - uri = - path::join(os::realpath(dirname(argv[0])).get(), "long-lived-executor"); + uri = path::join( + os::realpath(Path(argv[0]).dirname()).get(), + "long-lived-executor"); } ExecutorInfo executor; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/low_level_scheduler_libprocess.cpp ---------------------------------------------------------------------- diff --git a/src/examples/low_level_scheduler_libprocess.cpp b/src/examples/low_level_scheduler_libprocess.cpp index fe4eb29..bd7d304 100644 --- a/src/examples/low_level_scheduler_libprocess.cpp +++ b/src/examples/low_level_scheduler_libprocess.cpp @@ -43,6 +43,7 @@ #include <stout/option.hpp> #include <stout/os.hpp> #include <stout/option.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include "common/status_utils.hpp" @@ -335,7 +336,7 @@ private: void usage(const char* argv0, const flags::FlagsBase& flags) { - cerr << "Usage: " << os::basename(argv0).get() << " [...]" << endl + cerr << "Usage: " << Path(argv0).basename() << " [...]" << endl << endl << "Supported options:" << endl << flags.usage(); @@ -350,8 +351,10 @@ int main(int argc, char** argv) if (value.isSome()) { uri = path::join(value.get(), "src", "test-executor"); } else { - uri = - path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor"); + uri = path::join( + os::realpath(Path(argv[0]).dirname()).get(), + "src", + "test-executor"); } mesos::internal::logging::Flags flags; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/low_level_scheduler_pthread.cpp ---------------------------------------------------------------------- diff --git a/src/examples/low_level_scheduler_pthread.cpp b/src/examples/low_level_scheduler_pthread.cpp index 1d285d8..0513834 100644 --- a/src/examples/low_level_scheduler_pthread.cpp +++ b/src/examples/low_level_scheduler_pthread.cpp @@ -41,6 +41,7 @@ #include <stout/numify.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include "common/status_utils.hpp" @@ -392,7 +393,7 @@ private: void usage(const char* argv0, const flags::FlagsBase& flags) { - cerr << "Usage: " << os::basename(argv0).get() << " [...]" << endl + cerr << "Usage: " << Path(argv0).basename() << " [...]" << endl << endl << "Supported options:" << endl << flags.usage(); @@ -408,7 +409,10 @@ int main(int argc, char** argv) uri = path::join(value.get(), "src", "test-executor"); } else { uri = - path::join(os::realpath(dirname(argv[0])).get(), "src", "test-executor"); + path::join( + os::realpath(Path(argv[0]).dirname()).get(), + "src", + "test-executor"); } mesos::internal::logging::Flags flags; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/persistent_volume_framework.cpp ---------------------------------------------------------------------- diff --git a/src/examples/persistent_volume_framework.cpp b/src/examples/persistent_volume_framework.cpp index ee2311f..c6d6ed3 100644 --- a/src/examples/persistent_volume_framework.cpp +++ b/src/examples/persistent_volume_framework.cpp @@ -33,6 +33,7 @@ #include <stout/json.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/stringify.hpp> #include <stout/uuid.hpp> @@ -461,7 +462,7 @@ int main(int argc, char** argv) // Configure slave. os::setenv("MESOS_DEFAULT_ROLE", flags.role); - const string launcherDir = os::dirname(os::realpath(argv[0]).get()).get(); + const string launcherDir = Path(os::realpath(argv[0]).get()).dirname(); os::setenv("MESOS_LAUNCHER_DIR", launcherDir); os::libraries::appendPaths(launcherDir); } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/examples/test_framework.cpp ---------------------------------------------------------------------- diff --git a/src/examples/test_framework.cpp b/src/examples/test_framework.cpp index 99b981d..8b16ebe 100644 --- a/src/examples/test_framework.cpp +++ b/src/examples/test_framework.cpp @@ -33,6 +33,7 @@ #include <stout/numify.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include "logging/flags.hpp" @@ -186,7 +187,7 @@ private: void usage(const char* argv0, const flags::FlagsBase& flags) { - cerr << "Usage: " << os::basename(argv0).get() << " [...]" << endl + cerr << "Usage: " << Path(argv0).basename() << " [...]" << endl << endl << "Supported options:" << endl << flags.usage(); @@ -201,7 +202,9 @@ int main(int argc, char** argv) if (value.isSome()) { uri = path::join(value.get(), "src", "test-executor"); } else { - uri = path::join(os::realpath(dirname(argv[0])).get(), "test-executor"); + uri = path::join( + os::realpath(Path(argv[0]).dirname()).get(), + "test-executor"); } mesos::internal::logging::Flags flags; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/files/files.cpp ---------------------------------------------------------------------- diff --git a/src/files/files.cpp b/src/files/files.cpp index 3cdd38a..3a62ee7 100644 --- a/src/files/files.cpp +++ b/src/files/files.cpp @@ -406,23 +406,19 @@ Future<Response> FilesProcess::download(const Request& request) return BadRequest("Cannot download a directory.\n"); } - Try<string> basename = os::basename(resolvedPath.get()); - if (basename.isError()) { - LOG(ERROR) << basename.error(); - return InternalServerError(basename.error() + ".\n"); - } + string basename = Path(resolvedPath.get()).basename(); OK response; response.type = response.PATH; response.path = resolvedPath.get(); response.headers["Content-Type"] = "application/octet-stream"; response.headers["Content-Disposition"] = - strings::format("attachment; filename=%s", basename.get()).get(); + strings::format("attachment; filename=%s", basename).get(); // Attempt to detect the mime type. - size_t index = basename.get().find_last_of('.'); + size_t index = basename.find_last_of('.'); if (index != string::npos) { - string extension = basename.get().substr(index); + string extension = basename.substr(index); if (mime::types.count(extension) > 0) { response.headers["Content-Type"] = mime::types[extension]; } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/health-check/main.cpp ---------------------------------------------------------------------- diff --git a/src/health-check/main.cpp b/src/health-check/main.cpp index 3607479..857764a 100644 --- a/src/health-check/main.cpp +++ b/src/health-check/main.cpp @@ -41,6 +41,7 @@ #include <stout/json.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/strings.hpp> @@ -281,7 +282,7 @@ public: void usage(const char* argv0, const flags::FlagsBase& flags) { - cerr << "Usage: " << os::basename(argv0).get() << " [...]" << endl + cerr << "Usage: " << Path(argv0).basename() << " [...]" << endl << endl << "Supported options:" << endl << flags.usage(); http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/launcher/executor.cpp ---------------------------------------------------------------------- diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp index 9a3a1c3..9fa7dcf 100644 --- a/src/launcher/executor.cpp +++ b/src/launcher/executor.cpp @@ -46,6 +46,7 @@ #include <stout/lambda.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/strings.hpp> #include "common/http.hpp" @@ -632,8 +633,9 @@ int main(int argc, char** argv) } const Option<string> envPath = os::getenv("MESOS_LAUNCHER_DIR"); - string path = envPath.isSome() ? envPath.get() - : os::realpath(dirname(argv[0])).get(); + string path = + envPath.isSome() ? envPath.get() + : os::realpath(Path(argv[0]).dirname()).get(); mesos::internal::CommandExecutor executor(override, path); mesos::MesosExecutorDriver driver(&executor); return driver.run() == mesos::DRIVER_STOPPED ? EXIT_SUCCESS : EXIT_FAILURE; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/linux/cgroups.cpp ---------------------------------------------------------------------- diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp index 6a87ac4..4c006d0 100644 --- a/src/linux/cgroups.cpp +++ b/src/linux/cgroups.cpp @@ -304,13 +304,8 @@ static Try<Nothing> create( "Failed to determine if hierarchy '" + hierarchy + "' has the 'cpuset' subsystem attached: " + attached.error()); } else if (attached.get().count("cpuset") > 0) { - Try<string> parent = os::dirname(path::join("/", cgroup)); - if (parent.isError()) { - return Error( - "Failed to determine parent cgroup of " + cgroup + - ": " + parent.error()); - } - return cloneCpusetCpusMems(hierarchy, parent.get(), cgroup); + string parent = Path(path::join("/", cgroup)).dirname(); + return cloneCpusetCpusMems(hierarchy, parent, cgroup); } return Nothing(); http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/local/main.cpp ---------------------------------------------------------------------- diff --git a/src/local/main.cpp b/src/local/main.cpp index ec21ed0..18b2f01 100644 --- a/src/local/main.cpp +++ b/src/local/main.cpp @@ -22,6 +22,7 @@ #include <string> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include "local/flags.hpp" @@ -55,7 +56,7 @@ int main(int argc, char **argv) local::Flags flags; flags.setUsageMessage( - "Usage: " + os::basename(argv[0]).get() + " [...]\n\n" + + "Usage: " + Path(argv[0]).basename() + " [...]\n\n" + "Launches an in-memory cluster within a single process."); // The following flags are executable specific (e.g., since we only http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/logging/logging.cpp ---------------------------------------------------------------------- diff --git a/src/logging/logging.cpp b/src/logging/logging.cpp index 6b14575..fb79867 100644 --- a/src/logging/logging.cpp +++ b/src/logging/logging.cpp @@ -218,18 +218,12 @@ Try<string> getLogFile(google::LogSeverity severity) return Error("The 'log_dir' option was not specified"); } - Try<string> basename = os::basename(argv0); - if (basename.isError()) { - return Error(basename.error()); - } - if (severity < 0 || google::NUM_SEVERITIES <= severity) { return Error("Unknown log severity: " + stringify(severity)); } - string suffix(google::GetLogSeverityName(severity)); - - return path::join(FLAGS_log_dir, basename.get()) + "." + suffix; + return path::join(FLAGS_log_dir, Path(argv0).basename()) + "." + + google::GetLogSeverityName(severity); } } // namespace logging { http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/fetcher.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp index f77652b..6bafa33 100644 --- a/src/slave/containerizer/fetcher.cpp +++ b/src/slave/containerizer/fetcher.cpp @@ -126,7 +126,7 @@ Try<string> Fetcher::basename(const string& uri) return path.substr(path.find_last_of("/") + 1); } - return os::basename(uri); + return Path(uri).basename(); } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/isolators/cgroups/cpushare.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/cgroups/cpushare.cpp b/src/slave/containerizer/isolators/cgroups/cpushare.cpp index 21e4284..f56e97d 100644 --- a/src/slave/containerizer/isolators/cgroups/cpushare.cpp +++ b/src/slave/containerizer/isolators/cgroups/cpushare.cpp @@ -36,6 +36,7 @@ #include <stout/hashset.hpp> #include <stout/nothing.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include <stout/try.hpp> @@ -223,7 +224,7 @@ Future<Nothing> CgroupsCpushareIsolatorProcess::recover( } ContainerID containerId; - containerId.set_value(os::basename(cgroup).get()); + containerId.set_value(Path(cgroup).basename()); if (infos.contains(containerId)) { continue; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/isolators/cgroups/mem.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/cgroups/mem.cpp b/src/slave/containerizer/isolators/cgroups/mem.cpp index 9d65bf5..b0e343f 100644 --- a/src/slave/containerizer/isolators/cgroups/mem.cpp +++ b/src/slave/containerizer/isolators/cgroups/mem.cpp @@ -37,6 +37,7 @@ #include <stout/hashset.hpp> #include <stout/lambda.hpp> #include <stout/nothing.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include <stout/try.hpp> @@ -209,7 +210,7 @@ Future<Nothing> CgroupsMemIsolatorProcess::recover( } ContainerID containerId; - containerId.set_value(os::basename(cgroup).get()); + containerId.set_value(Path(cgroup).basename()); if (infos.contains(containerId)) { continue; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/isolators/cgroups/perf_event.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/cgroups/perf_event.cpp b/src/slave/containerizer/isolators/cgroups/perf_event.cpp index 3e5153f..512df3b 100644 --- a/src/slave/containerizer/isolators/cgroups/perf_event.cpp +++ b/src/slave/containerizer/isolators/cgroups/perf_event.cpp @@ -43,6 +43,7 @@ #include <stout/lambda.hpp> #include <stout/nothing.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/stringify.hpp> #include <stout/try.hpp> @@ -198,7 +199,7 @@ Future<Nothing> CgroupsPerfEventIsolatorProcess::recover( } ContainerID containerId; - containerId.set_value(os::basename(cgroup).get()); + containerId.set_value(Path(cgroup).basename()); if (infos.contains(containerId)) { continue; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/isolators/network/port_mapping.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/network/port_mapping.cpp b/src/slave/containerizer/isolators/network/port_mapping.cpp index f8018f2..2ef79eb 100644 --- a/src/slave/containerizer/isolators/network/port_mapping.cpp +++ b/src/slave/containerizer/isolators/network/port_mapping.cpp @@ -44,6 +44,7 @@ #include <stout/numify.hpp> #include <stout/os.hpp> #include <stout/option.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/result.hpp> #include <stout/stringify.hpp> @@ -310,13 +311,10 @@ static Try<ContainerID> getContainerIdFromSymlink(const string& symlink) return Error("Not a symlink"); } - Try<string> _containerId = os::basename(symlink); - if (_containerId.isError()) { - return Error("Failed to get the basename: " + _containerId.error()); - } + string _containerId = Path(symlink).basename(); ContainerID containerId; - containerId.set_value(_containerId.get()); + containerId.set_value(_containerId); return containerId; } @@ -330,12 +328,9 @@ static Result<pid_t> getPidFromNamespaceHandle(const string& handle) return Error("Not expecting a symlink"); } - Try<string> _pid = os::basename(handle); - if (_pid.isError()) { - return Error("Failed to get the basename: " + _pid.error()); - } + string _pid = Path(handle).basename(); - Try<pid_t> pid = numify<pid_t>(_pid.get()); + Try<pid_t> pid = numify<pid_t>(_pid); if (pid.isError()) { return None(); } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/containerizer/linux_launcher.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/linux_launcher.cpp b/src/slave/containerizer/linux_launcher.cpp index 7b24db8..790e392 100644 --- a/src/slave/containerizer/linux_launcher.cpp +++ b/src/slave/containerizer/linux_launcher.cpp @@ -57,11 +57,10 @@ namespace slave { static ContainerID container(const string& cgroup) { - Try<string> basename = os::basename(cgroup); - CHECK_SOME(basename); + string basename = Path(cgroup).basename(); ContainerID containerId; - containerId.set_value(basename.get()); + containerId.set_value(basename); return containerId; } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/state.cpp ---------------------------------------------------------------------- diff --git a/src/slave/state.cpp b/src/slave/state.cpp index 8eda22a..fab47a7 100644 --- a/src/slave/state.cpp +++ b/src/slave/state.cpp @@ -12,6 +12,7 @@ #include <stout/none.hpp> #include <stout/numify.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/try.hpp> @@ -89,7 +90,7 @@ Result<State> recover(const string& rootDir, bool strict) } SlaveID slaveId; - slaveId.set_value(os::basename(directory.get()).get()); + slaveId.set_value(Path(directory.get()).basename()); Try<SlaveState> slave = SlaveState::recover(rootDir, slaveId, strict); if (slave.isError()) { @@ -153,7 +154,7 @@ Try<SlaveState> SlaveState::recover( // Recover each of the frameworks. foreach (const string& path, frameworks.get()) { FrameworkID frameworkId; - frameworkId.set_value(os::basename(path).get()); + frameworkId.set_value(Path(path).basename()); Try<FrameworkState> framework = FrameworkState::recover(rootDir, slaveId, frameworkId, strict); @@ -262,7 +263,7 @@ Try<FrameworkState> FrameworkState::recover( // Recover the executors. foreach (const string& path, executors.get()) { ExecutorID executorId; - executorId.set_value(os::basename(path).get()); + executorId.set_value(Path(path).basename()); Try<ExecutorState> executor = ExecutorState::recover(rootDir, slaveId, frameworkId, executorId, strict); @@ -305,7 +306,7 @@ Try<ExecutorState> ExecutorState::recover( // Recover the runs. foreach (const string& path, runs.get()) { - if (os::basename(path).get() == paths::LATEST_SYMLINK) { + if (Path(path).basename() == paths::LATEST_SYMLINK) { const Result<string>& latest = os::realpath(path); if (!latest.isSome()) { return Error( @@ -318,11 +319,11 @@ Try<ExecutorState> ExecutorState::recover( // Store the ContainerID of the latest executor run. ContainerID containerId; - containerId.set_value(os::basename(latest.get()).get()); + containerId.set_value(Path(latest.get()).basename()); state.latest = containerId; } else { ContainerID containerId; - containerId.set_value(os::basename(path).get()); + containerId.set_value(Path(path).basename()); Try<RunState> run = RunState::recover( rootDir, slaveId, frameworkId, executorId, containerId, strict); @@ -425,7 +426,7 @@ Try<RunState> RunState::recover( // Recover tasks. foreach (const string& path, tasks.get()) { TaskID taskId; - taskId.set_value(os::basename(path).get()); + taskId.set_value(Path(path).basename()); Try<TaskState> task = TaskState::recover( rootDir, slaveId, frameworkId, executorId, containerId, taskId, strict); http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/state.hpp ---------------------------------------------------------------------- diff --git a/src/slave/state.hpp b/src/slave/state.hpp index fed4b7e..bb0eee7 100644 --- a/src/slave/state.hpp +++ b/src/slave/state.hpp @@ -32,6 +32,7 @@ #include <stout/hashmap.hpp> #include <stout/hashset.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/strings.hpp> #include <stout/utils.hpp> @@ -122,15 +123,11 @@ template <typename T> Try<Nothing> checkpoint(const std::string& path, const T& t) { // Create the base directory. - Try<std::string> base = os::dirname(path); - if (base.isError()) { - return Error("Failed to get the base directory path: " + base.error()); - } + std::string base = Path(path).dirname(); - Try<Nothing> mkdir = os::mkdir(base.get()); + Try<Nothing> mkdir = os::mkdir(base); if (mkdir.isError()) { - return Error("Failed to create directory '" + base.get() + - "': " + mkdir.error()); + return Error("Failed to create directory '" + base + "': " + mkdir.error()); } // NOTE: We create the temporary file at 'base/XXXXXX' to make sure @@ -139,7 +136,7 @@ Try<Nothing> checkpoint(const std::string& path, const T& t) // TODO(jieyu): It's possible that the temporary file becomes // dangling if slave crashes or restarts while checkpointing. // Consider adding a way to garbage collect them. - Try<std::string> temp = os::mktemp(path::join(base.get(), "XXXXXX")); + Try<std::string> temp = os::mktemp(path::join(base, "XXXXXX")); if (temp.isError()) { return Error("Failed to create temporary file: " + temp.error()); } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/slave/status_update_manager.cpp ---------------------------------------------------------------------- diff --git a/src/slave/status_update_manager.cpp b/src/slave/status_update_manager.cpp index 35b943b..0ad2450 100644 --- a/src/slave/status_update_manager.cpp +++ b/src/slave/status_update_manager.cpp @@ -27,6 +27,7 @@ #include <stout/lambda.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/stringify.hpp> #include <stout/utils.hpp> @@ -667,9 +668,9 @@ StatusUpdateStream::StatusUpdateStream( taskId); // Create the base updates directory, if it doesn't exist. - Try<Nothing> directory = os::mkdir(os::dirname(path.get()).get()); + Try<Nothing> directory = os::mkdir(Path(path.get()).dirname()); if (directory.isError()) { - error = "Failed to create " + os::dirname(path.get()).get(); + error = "Failed to create " + Path(path.get()).dirname(); return; } http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/tests/fetcher_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp index 361d918..ae10c42 100644 --- a/src/tests/fetcher_tests.cpp +++ b/src/tests/fetcher_tests.cpp @@ -34,6 +34,7 @@ #include <stout/net.hpp> #include <stout/option.hpp> #include <stout/os.hpp> +#include <stout/path.hpp> #include <stout/protobuf.hpp> #include <stout/strings.hpp> #include <stout/try.hpp> @@ -378,11 +379,9 @@ TEST_F(FetcherTest, NoExtractNotExecutable) containerId, commandInfo, os::getcwd(), None(), slaveId, flags); AWAIT_READY(fetch); - Try<string> basename = os::basename(path.get()); + string basename = Path(path.get()).basename(); - ASSERT_SOME(basename); - - Try<os::Permissions> permissions = os::permissions(basename.get()); + Try<os::Permissions> permissions = os::permissions(basename); ASSERT_SOME(permissions); EXPECT_FALSE(permissions.get().owner.x); @@ -420,11 +419,9 @@ TEST_F(FetcherTest, NoExtractExecutable) AWAIT_READY(fetch); - Try<string> basename = os::basename(path.get()); - - ASSERT_SOME(basename); + string basename = Path(path.get()).basename(); - Try<os::Permissions> permissions = os::permissions(basename.get()); + Try<os::Permissions> permissions = os::permissions(basename); ASSERT_SOME(permissions); EXPECT_TRUE(permissions.get().owner.x); http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/tests/mesos.cpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp index 2cd2435..5eab6de 100644 --- a/src/tests/mesos.cpp +++ b/src/tests/mesos.cpp @@ -687,7 +687,7 @@ void ContainerizerTest<slave::MesosContainerizer>::SetUp() ASSERT_FALSE(hierarchy.isError()); if (hierarchy.isSome()) { - Try<string> _baseHierarchy = os::dirname(hierarchy.get()); + Try<string> _baseHierarchy = Path(hierarchy.get()).dirname(); ASSERT_SOME(_baseHierarchy) << "Failed to get the base of hierarchy '" << hierarchy.get() << "'"; http://git-wip-us.apache.org/repos/asf/mesos/blob/505d3838/src/zookeeper/group.cpp ---------------------------------------------------------------------- diff --git a/src/zookeeper/group.cpp b/src/zookeeper/group.cpp index 33c56da..01066e3 100644 --- a/src/zookeeper/group.cpp +++ b/src/zookeeper/group.cpp @@ -590,15 +590,12 @@ Result<Group::Membership> GroupProcess::doJoin( // Save the sequence number but only grab the basename. Example: // "/path/to/znode/label_0000000131" => "0000000131". - Try<string> basename = os::basename(result); - if (basename.isError()) { - return Error("Failed to get the sequence number: " + basename.error()); - } + string basename = Path(result).basename(); // Strip the label before grabbing the sequence number. string node = label.isSome() - ? strings::remove(basename.get(), label.get() + "_") - : basename.get(); + ? strings::remove(basename, label.get() + "_") + : basename; Try<int32_t> sequence = numify<int32_t>(node); CHECK_SOME(sequence);
