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/29 03:05:20 UTC
[1/2] mesos git commit: Stout: Added missing 'filesystem_tests.cpp'
to Makefile.
Repository: mesos
Updated Branches:
refs/heads/master ebc85487c -> 3f6dfe713
Stout: Added missing 'filesystem_tests.cpp' to Makefile.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3f6dfe71
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3f6dfe71
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3f6dfe71
Branch: refs/heads/master
Commit: 3f6dfe7133e2b49f89b31e9425bee04795d21f06
Parents: 214af2a
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Thu Jan 28 18:03:43 2016 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Jan 28 18:05:12 2016 -0800
----------------------------------------------------------------------
3rdparty/libprocess/3rdparty/Makefile.am | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3f6dfe71/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index b7bed0b..42c95a9 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -173,7 +173,7 @@ stout_tests_SOURCES = \
$(STOUT)/tests/interval_tests.cpp \
$(STOUT)/tests/ip_tests.cpp \
$(STOUT)/tests/json_tests.cpp \
- $(STOUT)/tests/jsonify_tests.cpp \
+ $(STOUT)/tests/jsonify_tests.cpp \
$(STOUT)/tests/linkedhashmap_tests.cpp \
$(STOUT)/tests/mac_tests.cpp \
$(STOUT)/tests/main.cpp \
@@ -182,6 +182,7 @@ stout_tests_SOURCES = \
$(STOUT)/tests/numify_tests.cpp \
$(STOUT)/tests/option_tests.cpp \
$(STOUT)/tests/os_tests.cpp \
+ $(STOUT)/tests/os/filesystem_tests.cpp \
$(STOUT)/tests/os/sendfile_tests.cpp \
$(STOUT)/tests/os/signals_tests.cpp \
$(STOUT)/tests/os/strerror_tests.cpp \
[2/2] mesos git commit: Windows: Implemented size(),
usage() and symlink().
Posted by jo...@apache.org.
Windows: Implemented size(), usage() and symlink().
Review: https://reviews.apache.org/r/40718/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/214af2ac
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/214af2ac
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/214af2ac
Branch: refs/heads/master
Commit: 214af2ac3b07468083c990a3c9d1a7f76f0839cb
Parents: ebc8548
Author: Alex Naparu <al...@outlook.com>
Authored: Thu Jan 28 17:53:31 2016 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Jan 28 18:05:12 2016 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/Makefile.am | 2 +
.../3rdparty/stout/include/stout/fs.hpp | 55 ++-----------
.../3rdparty/stout/include/stout/posix/fs.hpp | 65 +++++++++++++++
.../3rdparty/stout/include/stout/windows/fs.hpp | 86 ++++++++++++++++++++
.../stout/tests/os/filesystem_tests.cpp | 19 +++++
5 files changed, 179 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/214af2ac/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 1c452fb..8eef318 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -128,6 +128,7 @@ nobase_include_HEADERS = \
stout/preprocessor.hpp \
stout/proc.hpp \
stout/protobuf.hpp \
+ stout/posix/fs.hpp \
stout/posix/gzip.hpp \
stout/posix/os.hpp \
stout/recordio.hpp \
@@ -153,5 +154,6 @@ nobase_include_HEADERS = \
stout/windows.hpp \
stout/windows/error.hpp \
stout/windows/format.hpp \
+ stout/windows/fs.hpp \
stout/windows/gzip.hpp \
stout/windows/os.hpp
http://git-wip-us.apache.org/repos/asf/mesos/blob/214af2ac/3rdparty/libprocess/3rdparty/stout/include/stout/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/fs.hpp
index 2e26f15..0e11fb8 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/fs.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/fs.hpp
@@ -13,54 +13,13 @@
#ifndef __STOUT_FS_HPP__
#define __STOUT_FS_HPP__
-#include <unistd.h> // For symlink.
+// 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/windows/fs.hpp>
+#else
+#include <stout/posix/fs.hpp>
+#endif // __WINDOWS__
-#include <sys/statvfs.h>
-
-#include <string>
-
-#include "bytes.hpp"
-#include "error.hpp"
-#include "nothing.hpp"
-#include "try.hpp"
-
-// TODO(bmahler): Merge available() and usage() into df() that returns
-// a struct, and move this back into os.hpp.
-namespace fs {
-
-// Returns the total disk size in bytes.
-inline Try<Bytes> size(const std::string& path = "/")
-{
- struct statvfs buf;
- if (::statvfs(path.c_str(), &buf) < 0) {
- return ErrnoError();
- }
- return Bytes(buf.f_blocks * buf.f_frsize);
-}
-
-
-// Returns relative disk usage of the file system that the given path
-// is mounted at.
-inline Try<double> usage(const std::string& path = "/")
-{
- struct statvfs buf;
- if (statvfs(path.c_str(), &buf) < 0) {
- return ErrnoError("Error invoking statvfs on '" + path + "'");
- }
- return (double) (buf.f_blocks - buf.f_bfree) / buf.f_blocks;
-}
-
-
-inline Try<Nothing> symlink(
- const std::string& original,
- const std::string& link)
-{
- if (::symlink(original.c_str(), link.c_str()) < 0) {
- return ErrnoError();
- }
- return Nothing();
-}
-
-} // namespace fs {
#endif // __STOUT_FS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/214af2ac/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
new file mode 100644
index 0000000..b8c5731
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
@@ -0,0 +1,65 @@
+// 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_POSIX_FS_HPP__
+#define __STOUT_POSIX_FS_HPP__
+
+#include <unistd.h> // For symlink.
+#include <sys/statvfs.h>
+
+#include <string>
+
+#include <stout/bytes.hpp>
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+// TODO(bmahler): Merge available() and usage() into df() that returns
+// a struct, and move this back into os.hpp.
+namespace fs {
+
+// Returns the total disk size in bytes.
+inline Try<Bytes> size(const std::string& path = "/")
+{
+ struct statvfs buf;
+ if (::statvfs(path.c_str(), &buf) < 0) {
+ return ErrnoError();
+ }
+ return Bytes(buf.f_blocks * buf.f_frsize);
+}
+
+
+// Returns relative disk usage of the file system that the given path
+// is mounted at.
+inline Try<double> usage(const std::string& path = "/")
+{
+ struct statvfs buf;
+ if (statvfs(path.c_str(), &buf) < 0) {
+ return ErrnoError("Error invoking statvfs on '" + path + "'");
+ }
+ return (double) (buf.f_blocks - buf.f_bfree) / buf.f_blocks;
+}
+
+
+inline Try<Nothing> symlink(
+ const std::string& original,
+ const std::string& link)
+{
+ if (::symlink(original.c_str(), link.c_str()) < 0) {
+ return ErrnoError();
+ }
+ return Nothing();
+}
+
+} // namespace fs {
+
+#endif // __STOUT_POSIX_FS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/214af2ac/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
new file mode 100644
index 0000000..61bc0ce
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
@@ -0,0 +1,86 @@
+// 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_WINDOWS_FS_HPP__
+#define __STOUT_WINDOWS_FS_HPP__
+
+#include <string>
+
+#include <stout/bytes.hpp>
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+#include <stout/internal/windows/symlink.hpp>
+
+namespace fs {
+
+// Returns the total disk size in bytes.
+inline Try<Bytes> size(const std::string& path = "/")
+{
+ Result<std::string> real_path = os::realpath(path);
+ if (!real_path.isSome()) {
+ return Error(
+ "Failed to get realpath for '" + path+ "': " +
+ (real_path.isError() ? real_path.error() : "No such directory"));
+ }
+
+ ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
+ if (::GetDiskFreeSpaceEx(
+ real_path.get().c_str(),
+ &free_bytes,
+ &total_bytes,
+ &total_free_bytes) == 0) {
+ return WindowsError(
+ "Error invoking 'GetDiskFreeSpaceEx' on '" + path + "'");
+ }
+
+ return Bytes(total_bytes.QuadPart);
+}
+
+
+// Returns relative disk usage of the file system that the given path
+// is mounted at.
+inline Try<double> usage(const std::string& path = "/")
+{
+ Result<std::string> real_path = os::realpath(path);
+ if (!real_path.isSome()) {
+ return Error(
+ "Failed to get realpath for '" + path + "': " +
+ (real_path.isError() ? real_path.error() : "No such directory"));
+ }
+
+ ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
+ if (::GetDiskFreeSpaceEx(
+ real_path.get().c_str(),
+ &free_bytes,
+ &total_bytes,
+ &total_free_bytes) == 0) {
+ return WindowsError(
+ "Error invoking 'GetDiskFreeSpaceEx' on '" + path + "'");
+ }
+
+ double used = total_bytes.QuadPart - free_bytes.QuadPart;
+ return used / total_bytes.QuadPart;
+}
+
+
+inline Try<Nothing> symlink(
+ const std::string& original,
+ const std::string& link)
+{
+ return internal::windows::create_symbolic_link(original, link);
+}
+
+} // namespace fs {
+
+#endif // __STOUT_WINDOWS_FS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/214af2ac/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
index c5ffd01..4c72e18 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -16,6 +16,7 @@
#include <string>
#include <stout/foreach.hpp>
+#include <stout/fs.hpp>
#include <stout/hashset.hpp>
#include <stout/path.hpp>
#include <stout/try.hpp>
@@ -140,3 +141,21 @@ TEST_F(FsTest, Touch)
ASSERT_SOME(os::touch(testfile));
ASSERT_TRUE(os::exists(testfile));
}
+
+TEST_F(FsTest, Symlink)
+{
+ const string temp_path = os::getcwd();
+ const string link = path::join(temp_path, "/sym.link");
+ const string file = path::join(temp_path, UUID::random().toString());
+
+ // Create file
+ ASSERT_SOME(os::touch(file))
+ << "Failed to create file '" << file << "'";
+ ASSERT_TRUE(os::exists(file));
+
+ // Create symlink
+ fs::symlink(file, link);
+
+ // Test symlink
+ EXPECT_TRUE(os::stat::islink(link));
+}