You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/01/13 22:35:59 UTC

mesos git commit: Windows: Implemented `os::dirent_size` to support `os::ls`.

Repository: mesos
Updated Branches:
  refs/heads/master c96923464 -> f7434f14e


Windows: Implemented `os::dirent_size` to support `os::ls`.

Review: https://reviews.apache.org/r/39802/


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

Branch: refs/heads/master
Commit: f7434f14e10277c9f03b4dd215c8c650ed895fd1
Parents: c969234
Author: Alex Clemmer <cl...@gmail.com>
Authored: Wed Jan 13 15:40:59 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Wed Jan 13 15:40:59 2016 -0500

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  5 +-
 .../stout/include/stout/os/direntsize.hpp       | 26 +++++++
 .../3rdparty/stout/include/stout/os/ls.hpp      | 60 +++++++++++++--
 .../stout/include/stout/os/posix/direntsize.hpp | 42 ++++++++++
 .../stout/include/stout/os/posix/ls.hpp         | 80 --------------------
 .../include/stout/os/windows/direntsize.hpp     | 43 +++++++++++
 .../stout/include/stout/os/windows/ls.hpp       | 29 -------
 7 files changed, 169 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 1307b0a..02437a4 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -57,6 +57,7 @@ nobase_include_HEADERS =		\
   stout/os/chdir.hpp			\
   stout/os/close.hpp			\
   stout/os/constants.hpp		\
+  stout/os/direntsize.hpp		\
   stout/os/environment.hpp		\
   stout/os/exists.hpp			\
   stout/os/fcntl.hpp			\
@@ -89,12 +90,12 @@ nobase_include_HEADERS =		\
   stout/os/utime.hpp			\
   stout/os/write.hpp			\
   stout/os/posix/bootid.hpp		\
+  stout/os/posix/direntsize.hpp		\
   stout/os/posix/exists.hpp		\
   stout/os/posix/fcntl.hpp		\
   stout/os/posix/fork.hpp		\
   stout/os/posix/ftruncate.hpp		\
   stout/os/posix/killtree.hpp		\
-  stout/os/posix/ls.hpp			\
   stout/os/posix/mkdtemp.hpp		\
   stout/os/posix/pstree.hpp		\
   stout/os/posix/sendfile.hpp		\
@@ -103,12 +104,12 @@ nobase_include_HEADERS =		\
   stout/os/posix/stat.hpp		\
   stout/os/raw/environment.hpp		\
   stout/os/windows/bootid.hpp		\
+  stout/os/windows/direntsize.hpp	\
   stout/os/windows/exists.hpp		\
   stout/os/windows/fcntl.hpp		\
   stout/os/windows/fork.hpp		\
   stout/os/windows/ftruncate.hpp	\
   stout/os/windows/killtree.hpp		\
-  stout/os/windows/ls.hpp		\
   stout/os/windows/mkdtemp.hpp		\
   stout/os/windows/pstree.hpp		\
   stout/os/windows/sendfile.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/direntsize.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/direntsize.hpp
new file mode 100644
index 0000000..819f99a
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/direntsize.hpp
@@ -0,0 +1,26 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_DIRENTSIZE_HPP__
+#define __STOUT_OS_DIRENTSIZE_HPP__
+
+
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specifc system calls into separate directories.
+#ifdef __WINDOWS__
+#include <stout/os/windows/direntsize.hpp>
+#else
+#include <stout/os/posix/direntsize.hpp>
+#endif // __WINDOWS__
+
+
+#endif // __STOUT_OS_DIRENTSIZE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/ls.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/ls.hpp
index 7be7d12..216a4fc 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/ls.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/ls.hpp
@@ -13,14 +13,64 @@
 #ifndef __STOUT_OS_LS_HPP__
 #define __STOUT_OS_LS_HPP__
 
-
-// For readability, we minimize the number of #ifdef blocks in the code by
-// splitting platform specifc system calls into separate directories.
 #ifdef __WINDOWS__
-#include <stout/os/windows/ls.hpp>
+#include <stout/internal/windows/dirent.hpp>
 #else
-#include <stout/os/posix/ls.hpp>
+#include <dirent.h>
 #endif // __WINDOWS__
+#include <stdlib.h>
+
+#include <list>
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/direntsize.hpp>
+
+
+namespace os {
+
+inline Try<std::list<std::string>> ls(const std::string& directory)
+{
+  DIR* dir = opendir(directory.c_str());
+
+  if (dir == NULL) {
+    // Preserve `opendir` error.
+    return ErrnoError("Failed to opendir '" + directory + "'");
+  }
+
+  dirent* temp = (dirent*) malloc(os::dirent_size(dir));
+
+  if (temp == NULL) {
+    // Preserve `malloc` error.
+    ErrnoError error("Failed to allocate directory entries");
+    closedir(dir);
+    return error;
+  }
+
+  std::list<std::string> result;
+  struct dirent* entry;
+  int error;
+
+  while ((error = readdir_r(dir, temp, &entry)) == 0 && entry != NULL) {
+    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+      continue;
+    }
+    result.push_back(entry->d_name);
+  }
+
+  free(temp);
+  closedir(dir);
+
+  if (error != 0) {
+    // Preserve `readdir_r` error.
+    return ErrnoError("Failed to read directories");
+  }
+
+  return result;
+}
 
+} // namespace os {
 
 #endif // __STOUT_OS_LS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/direntsize.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/direntsize.hpp
new file mode 100644
index 0000000..9d8f72e
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/direntsize.hpp
@@ -0,0 +1,42 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_DIRENTSIZE_HPP__
+#define __STOUT_OS_POSIX_DIRENTSIZE_HPP__
+
+#include <dirent.h>
+#include <unistd.h>
+
+
+namespace os {
+
+inline size_t dirent_size(DIR* dir)
+{
+  // Calculate the size for a "directory entry".
+  long name_max = fpathconf(dirfd(dir), _PC_NAME_MAX);
+
+  // If we don't get a valid size, check NAME_MAX, but fall back on
+  // 255 in the worst case ... Danger, Will Robinson!
+  if (name_max == -1) {
+    name_max = (NAME_MAX > 255) ? NAME_MAX : 255;
+  }
+
+  size_t name_end = (size_t) offsetof(dirent, d_name) + name_max + 1;
+
+  size_t size = (name_end > sizeof(dirent) ? name_end : sizeof(dirent));
+
+  return size;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_DIRENTSIZE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/ls.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/ls.hpp
deleted file mode 100644
index fcc6986..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/ls.hpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//  http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef __STOUT_OS_POSIX_LS_HPP__
-#define __STOUT_OS_POSIX_LS_HPP__
-
-#include <dirent.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <list>
-#include <string>
-
-
-namespace os {
-
-inline Try<std::list<std::string>> ls(const std::string& directory)
-{
-  DIR* dir = opendir(directory.c_str());
-
-  if (dir == NULL) {
-    return ErrnoError("Failed to opendir '" + directory + "'");
-  }
-
-  // Calculate the size for a "directory entry".
-  long name_max = fpathconf(dirfd(dir), _PC_NAME_MAX);
-
-  // If we don't get a valid size, check NAME_MAX, but fall back on
-  // 255 in the worst case ... Danger, Will Robinson!
-  if (name_max == -1) {
-    name_max = (NAME_MAX > 255) ? NAME_MAX : 255;
-  }
-
-  size_t name_end = (size_t) offsetof(dirent, d_name) + name_max + 1;
-
-  size_t size = (name_end > sizeof(dirent) ? name_end : sizeof(dirent));
-
-  dirent* temp = (dirent*) malloc(size);
-
-  if (temp == NULL) {
-    // Preserve malloc error.
-    ErrnoError error("Failed to allocate directory entries");
-    closedir(dir);
-    return error;
-  }
-
-  std::list<std::string> result;
-  struct dirent* entry;
-  int error;
-
-  while ((error = readdir_r(dir, temp, &entry)) == 0 && entry != NULL) {
-    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
-      continue;
-    }
-    result.push_back(entry->d_name);
-  }
-
-  free(temp);
-  closedir(dir);
-
-  if (error != 0) {
-    errno = error;
-    return ErrnoError("Failed to read directories");
-  }
-
-  return result;
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_POSIX_LS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/direntsize.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/direntsize.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/direntsize.hpp
new file mode 100644
index 0000000..7c8c7a0
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/direntsize.hpp
@@ -0,0 +1,43 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_DIRENTSIZE_HPP__
+#define __STOUT_OS_WINDOWS_DIRENTSIZE_HPP__
+
+#include <stout/internal/windows/dirent.hpp>
+
+#include <stout/windows.hpp>
+
+
+namespace os {
+
+inline size_t dirent_size(DIR* dir)
+{
+  // NOTE: Size calculation logic here is much simpler than on POSIX because
+  // our implementation of `dirent` is constant-sized. In particular, on POSIX,
+  // we usually have to calculate the maximum name size for a path before we
+  // can alloc a correctly-size `dirent`, but on Windows, `dirent.d_name` is
+  // always `MAX_PATH` bytes in size.
+  //
+  // This follows closely from the Windows standard API data structures for
+  // manipulating and querying directories. For example, the structures
+  // `WIN32_FIND_DATA`[1] (which in many ways is the Windows equivalent of
+  // `dirent`) has a field `cFileName` (which is much like `d_name`) that is
+  // also `MAX_PATH` in size.
+  //
+  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365740(v=vs.85).aspx
+  return sizeof(dirent);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_DIRENTSIZE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7434f14/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/ls.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/ls.hpp
deleted file mode 100644
index 5b41344..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/ls.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//  http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef __STOUT_OS_WINDOWS_LS_HPP__
-#define __STOUT_OS_WINDOWS_LS_HPP__
-
-#include <list>
-#include <string>
-
-
-namespace os {
-
-inline Try<std::list<std::string>> ls(const std::string& directory)
-{
-  UNIMPLEMENTED;
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_WINDOWS_LS_HPP__