You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/11/20 23:41:30 UTC
[08/10] mesos git commit: Fixed a few style issues in HDFS wrapper
code.
Fixed a few style issues in HDFS wrapper code.
Review: https://reviews.apache.org/r/40464
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d6781a4e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d6781a4e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d6781a4e
Branch: refs/heads/master
Commit: d6781a4e9a4f361a98e50980d3ed0a6ab4350208
Parents: 5749b80
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Nov 18 16:03:30 2015 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Nov 20 14:40:43 2015 -0800
----------------------------------------------------------------------
src/hdfs/hdfs.cpp | 38 ++++++++++++++++----------------------
src/hdfs/hdfs.hpp | 14 +++++++-------
2 files changed, 23 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6781a4e/src/hdfs/hdfs.cpp
----------------------------------------------------------------------
diff --git a/src/hdfs/hdfs.cpp b/src/hdfs/hdfs.cpp
index 49aa0eb..767735d 100644
--- a/src/hdfs/hdfs.cpp
+++ b/src/hdfs/hdfs.cpp
@@ -69,12 +69,10 @@ Try<bool> HDFS::available()
}
-Try<bool> HDFS::exists(string path)
+Try<bool> HDFS::exists(const string& path)
{
- path = absolutePath(path);
-
Try<string> command = strings::format(
- "%s fs -test -e '%s'", hadoop, path);
+ "%s fs -test -e '%s'", hadoop, absolutePath(path));
CHECK_SOME(command);
@@ -90,9 +88,9 @@ Try<bool> HDFS::exists(string path)
}
-Try<Bytes> HDFS::du(string path)
+Try<Bytes> HDFS::du(const string& _path)
{
- path = absolutePath(path);
+ const string path = absolutePath(_path);
Try<string> command = strings::format(
"%s fs -du '%s'", hadoop, path);
@@ -110,13 +108,13 @@ Try<Bytes> HDFS::du(string path)
return Error("HDFS du failed: " + out.error());
}
- // We expect 2 space-separated output fields; a number of bytes then the
- // name of the path we gave. The 'hadoop' command can emit various WARN
- // or other log messages, so we make an effort to scan for the field we
- // want.
+ // We expect 2 space-separated output fields; a number of bytes then
+ // the name of the path we gave. The 'hadoop' command can emit
+ // various WARN or other log messages, so we make an effort to scan
+ // for the field we want.
foreach (const string& line, strings::tokenize(out.get(), "\n")) {
- // Note that we use tokenize() rather than split() since fields can be
- // delimited by multiple spaces.
+ // Note that we use tokenize() rather than split() since fields
+ // can be delimited by multiple spaces.
vector<string> fields = strings::tokenize(line, " ");
if (fields.size() == 2 && fields[1] == path) {
@@ -135,12 +133,10 @@ Try<Bytes> HDFS::du(string path)
}
-Try<Nothing> HDFS::rm(string path)
+Try<Nothing> HDFS::rm(const string& path)
{
- path = absolutePath(path);
-
Try<string> command = strings::format(
- "%s fs -rm '%s'", hadoop, path);
+ "%s fs -rm '%s'", hadoop, absolutePath(path));
CHECK_SOME(command);
@@ -154,15 +150,14 @@ Try<Nothing> HDFS::rm(string path)
}
-Try<Nothing> HDFS::copyFromLocal(const string& from, string to)
+Try<Nothing> HDFS::copyFromLocal(const string& from, const string& _to)
{
if (!os::exists(from)) {
return Error("Failed to find " + from);
}
- to = absolutePath(to);
+ const string to = absolutePath(_to);
- // Copy to HDFS.
Try<string> command = strings::format(
"%s fs -copyFromLocal '%s' '%s'", hadoop, from, to);
@@ -178,11 +173,10 @@ Try<Nothing> HDFS::copyFromLocal(const string& from, string to)
}
-Try<Nothing> HDFS::copyToLocal(string from, const string& to)
+Try<Nothing> HDFS::copyToLocal(const string& _from, const string& to)
{
- from = absolutePath(from);
+ const string from = absolutePath(_from);
- // Copy from HDFS.
Try<string> command = strings::format(
"%s fs -copyToLocal '%s' '%s'", hadoop, from, to);
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6781a4e/src/hdfs/hdfs.hpp
----------------------------------------------------------------------
diff --git a/src/hdfs/hdfs.hpp b/src/hdfs/hdfs.hpp
index 488d2e1..aee6894 100644
--- a/src/hdfs/hdfs.hpp
+++ b/src/hdfs/hdfs.hpp
@@ -55,15 +55,15 @@ public:
// checking for status code == 0.
Try<bool> available();
- Try<bool> exists(std::string path);
- Try<Bytes> du(std::string path);
- Try<Nothing> rm(std::string path);
- Try<Nothing> copyFromLocal(const std::string& from, std::string to);
- Try<Nothing> copyToLocal(std::string from, const std::string& to);
+ Try<bool> exists(const std::string& path);
+ Try<Bytes> du(const std::string& path);
+ Try<Nothing> rm(const std::string& path);
+ Try<Nothing> copyFromLocal(const std::string& from, const std::string& to);
+ Try<Nothing> copyToLocal(const std::string& from, const std::string& to);
private:
- // Normalize an HDFS path such that it is either an absolute path
- // or a full hdfs:// URL.
+ // Normalize an HDFS path such that it is either an absolute path or
+ // a full hdfs:// URL.
std::string absolutePath(const std::string& hdfsPath);
const std::string hadoop;