kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] kudu git commit: KUDU-2205. Improve error message for failed globs
Date Tue, 31 Oct 2017 01:04:32 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 9f85f04a9 -> 563f41b5c


KUDU-2205. Improve error message for failed globs

This fixes the Env::Glob function to give a more understandable error
message on typical issues such as permission denied. This can improve
the diagnosability in the case that a server is started with an
inaccessible log directory.

Change-Id: Ib7e487b5f6b24c2a2bd66e33f5b51a31e6585657
Reviewed-on: http://gerrit.cloudera.org:8080/8415
Reviewed-by: Adar Dembo <adar@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/cb4b1c09
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/cb4b1c09
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/cb4b1c09

Branch: refs/heads/master
Commit: cb4b1c090da07c4f1c74c6c97665e564d3af2abe
Parents: 9f85f04
Author: Todd Lipcon <todd@apache.org>
Authored: Mon Oct 30 12:26:51 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Mon Oct 30 19:55:58 2017 +0000

----------------------------------------------------------------------
 src/kudu/util/env-test.cc  | 14 ++++++++++++++
 src/kudu/util/env_posix.cc |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/cb4b1c09/src/kudu/util/env-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env-test.cc b/src/kudu/util/env-test.cc
index 3e0517f..63c0e20 100644
--- a/src/kudu/util/env-test.cc
+++ b/src/kudu/util/env-test.cc
@@ -806,6 +806,20 @@ TEST_F(TestEnv, TestGlob) {
   }
 }
 
+// Test that the status returned when 'glob' fails with a permission
+// error is reasonable.
+TEST_F(TestEnv, TestGlobPermissionDenied) {
+  string dir = GetTestPath("glob");
+  ASSERT_OK(env_->CreateDir(dir));
+  chmod(dir.c_str(), 0000);
+  auto cleanup = MakeScopedCleanup([&]() {
+      chmod(dir.c_str(), 0700);
+    });
+  vector<string> matches;
+  Status s = env_->Glob(JoinPathSegments(dir, "*"), &matches);
+  ASSERT_STR_MATCHES(s.ToString(), "IO error: glob failed for /.*: Permission denied");
+}
+
 TEST_F(TestEnv, TestGetBlockSize) {
   uint64_t block_size;
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/cb4b1c09/src/kudu/util/env_posix.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index bd552f1..e4d479c 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -1504,12 +1504,18 @@ class PosixEnv : public Env {
     glob_t result;
     auto cleanup = MakeScopedCleanup([&] { globfree(&result); });
 
+    errno = 0;
     int ret = glob(path_pattern.c_str(), GLOB_TILDE | GLOB_ERR , NULL, &result);
     switch (ret) {
       case 0: break;
       case GLOB_NOMATCH: return Status::OK();
       case GLOB_NOSPACE: return Status::RuntimeError("glob out of memory");
-      default: return Status::IOError("glob failure", std::to_string(ret));
+      default: {
+        string err = (errno != 0) ? ErrnoToString(errno) : "unknown error";
+        return Status::IOError(Substitute("glob failed for $0: $1",
+                                          path_pattern,
+                                          err));
+      }
     }
 
     for (size_t i = 0; i < result.gl_pathc; ++i) {


Mime
View raw message