Refactored lambda in registry client. Review: https://reviews.apache.org/r/39016
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/df7dd722 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/df7dd722 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/df7dd722 Branch: refs/heads/master Commit: df7dd722af82ec928220d0bd85ccc57636d982dc Parents: af6504a Author: Jojy Varghese <[email protected]> Authored: Thu Nov 5 21:10:30 2015 -0800 Committer: Timothy Chen <[email protected]> Committed: Thu Nov 5 22:28:06 2015 -0800 ---------------------------------------------------------------------- .../provisioner/docker/registry_client.cpp | 38 +++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/df7dd722/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp index 7a83742..a8497f9 100644 --- a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp +++ b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp @@ -230,10 +230,9 @@ Try<http::Headers> RegistryClientProcess::getAuthenticationAttributes( strings::tokenize(authStringTokens[1], ","); http::Headers authenticationAttributes; - auto addAttribute = [&authenticationAttributes]( - const string& param) -> Try<Nothing> { - const vector<string> paramTokens = - strings::tokenize(param, "=\""); + + foreach (const string& param, authenticationParams) { + const vector<string> paramTokens = strings::tokenize(param, "=\""); if (paramTokens.size() != 2) { return Error( @@ -242,15 +241,6 @@ Try<http::Headers> RegistryClientProcess::getAuthenticationAttributes( } authenticationAttributes.insert({paramTokens[0], paramTokens[1]}); - - return Nothing(); - }; - - foreach (const string& param, authenticationParams) { - Try<Nothing> addRes = addAttribute(param); - if (addRes.isError()) { - return Error(addRes.error()); - } } return authenticationAttributes; @@ -616,24 +606,12 @@ Future<size_t> RegistryClientProcess::getBlob( const Option<string>& digest, const Path& filePath) { - auto prepare = ([&filePath]() -> Try<Nothing> { - const string dirName = filePath.dirname(); - - // TODO(jojy): Return more state, for example - if the directory is new. - Try<Nothing> dirResult = os::mkdir(dirName, true); - if (dirResult.isError()) { - return Error( - "Failed to create directory to download blob: " + - dirResult.error()); - } - - return dirResult; - })(); + const string dirName = filePath.dirname(); - // TODO(jojy): This currently leaves a residue in failure cases. Would be - // ideal if we can completely rollback. - if (prepare.isError()) { - return Failure(prepare.error()); + Try<Nothing> mkdir = os::mkdir(dirName, true); + if (mkdir.isError()) { + return Failure( + "Failed to create directory to download blob: " + mkdir.error()); } if (strings::contains(path, " ")) {
