You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by dm...@apache.org on 2014/07/30 21:04:04 UTC
[2/2] git commit: Fixes for stout ls returning Try.
Fixes for stout ls returning Try.
Review: https://reviews.apache.org/r/20500
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/aa16bbd9
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/aa16bbd9
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/aa16bbd9
Branch: refs/heads/master
Commit: aa16bbd907259e5761f3993b447197c3c7199999
Parents: 14cc94a
Author: Dominic Hamon <dh...@twitter.com>
Authored: Fri Apr 18 11:55:11 2014 -0700
Committer: Dominic Hamon <dh...@twitter.com>
Committed: Wed Jul 30 10:25:42 2014 -0700
----------------------------------------------------------------------
src/files/files.cpp | 22 +++++++++++++---------
src/slave/slave.cpp | 49 +++++++++++++++++++++++++-----------------------
2 files changed, 39 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/aa16bbd9/src/files/files.cpp
----------------------------------------------------------------------
diff --git a/src/files/files.cpp b/src/files/files.cpp
index 3dacc66..12e8f75 100644
--- a/src/files/files.cpp
+++ b/src/files/files.cpp
@@ -46,6 +46,7 @@ using process::http::OK;
using process::http::Response;
using process::http::Request;
+using std::list;
using std::map;
using std::string;
using std::vector;
@@ -71,7 +72,7 @@ private:
// Returns None if the file is not found.
// Returns Error if we find the file but it cannot be resolved or it breaks
// out of the chroot.
- Result<std::string> resolve(const string& path);
+ Result<string> resolve(const string& path);
// HTTP endpoints.
@@ -167,16 +168,19 @@ Future<Response> FilesProcess::browse(const Request& request)
// The result will be a sorted (on path) array of files and dirs:
// [{"name": "README", "path": "dir/README" "dir":False, "size":42}, ...]
map<string, JSON::Object> files;
- foreach (const string& filename, os::ls(resolvedPath.get())) {
- struct stat s;
- string fullPath = path::join(resolvedPath.get(), filename);
+ Try<list<string> > entries = os::ls(resolvedPath.get());
+ if (entries.isSome()) {
+ foreach (const string& entry, entries.get()) {
+ struct stat s;
+ string fullPath = path::join(resolvedPath.get(), entry);
+
+ if (stat(fullPath.c_str(), &s) < 0) {
+ PLOG(WARNING) << "Found " << fullPath << " in ls but stat failed";
+ continue;
+ }
- if (stat(fullPath.c_str(), &s) < 0) {
- PLOG(WARNING) << "Found " << fullPath << " in ls but stat failed";
- continue;
+ files[fullPath] = jsonFileInfo(path::join(path.get(), entry), s);
}
-
- files[fullPath] = jsonFileInfo(path::join(path.get(), filename), s);
}
JSON::Array listing;
http://git-wip-us.apache.org/repos/asf/mesos/blob/aa16bbd9/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 1d56918..d59c514 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -3144,34 +3144,37 @@ void Slave::__recover(const Future<Nothing>& future)
// in the recovery code, to recover all slaves instead of only
// the latest slave.
const string& directory = path::join(flags.work_dir, "slaves");
- foreach (const string& entry, os::ls(directory)) {
- string path = path::join(directory, entry);
- // Ignore non-directory entries.
- if (!os::isdir(path)) {
- continue;
- }
+ Try<list<string> > entries = os::ls(directory);
+ if (entries.isSome()) {
+ foreach (const string& entry, entries.get()) {
+ string path = path::join(directory, entry);
+ // Ignore non-directory entries.
+ if (!os::isdir(path)) {
+ continue;
+ }
- // We garbage collect a directory if either the slave has not
- // recovered its id (hence going to get a new id when it
- // registers with the master) or if it is an old work directory.
- SlaveID slaveId;
- slaveId.set_value(entry);
- if (!info.has_id() || !(slaveId == info.id())) {
- LOG(INFO) << "Garbage collecting old slave " << slaveId;
+ // We garbage collect a directory if either the slave has not
+ // recovered its id (hence going to get a new id when it
+ // registers with the master) or if it is an old work directory.
+ SlaveID slaveId;
+ slaveId.set_value(entry);
+ if (!info.has_id() || !(slaveId == info.id())) {
+ LOG(INFO) << "Garbage collecting old slave " << slaveId;
- // NOTE: We update the modification time of the slave work/meta
- // directories even though these are old because these
- // directories might not have been scheduled for gc before.
+ // NOTE: We update the modification time of the slave work/meta
+ // directories even though these are old because these
+ // directories might not have been scheduled for gc before.
- // GC the slave work directory.
- os::utime(path); // Update the modification time.
- garbageCollect(path);
-
- // GC the slave meta directory.
- path = paths::getSlavePath(metaDir, slaveId);
- if (os::exists(path)) {
+ // GC the slave work directory.
os::utime(path); // Update the modification time.
garbageCollect(path);
+
+ // GC the slave meta directory.
+ path = paths::getSlavePath(metaDir, slaveId);
+ if (os::exists(path)) {
+ os::utime(path); // Update the modification time.
+ garbageCollect(path);
+ }
}
}
}