You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2016/11/05 08:40:09 UTC
[2/6] mesos git commit: Added `setxattr()` and `getxattr()` in stout.
Added `setxattr()` and `getxattr()` in stout.
Review: https://reviews.apache.org/r/53041
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e3c12c4c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e3c12c4c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e3c12c4c
Branch: refs/heads/master
Commit: e3c12c4c3fabc64c8a3de9e514340bfb52237d69
Parents: 61de698
Author: Qian Zhang <zh...@cn.ibm.com>
Authored: Wed Oct 19 16:19:59 2016 +0800
Committer: Qian Zhang <zh...@gmail.com>
Committed: Sat Nov 5 16:18:29 2016 +0800
----------------------------------------------------------------------
3rdparty/stout/include/Makefile.am | 3 +
3rdparty/stout/include/stout/os.hpp | 1 +
3rdparty/stout/include/stout/os/posix/xattr.hpp | 99 ++++++++++++++++++++
.../stout/include/stout/os/windows/xattr.hpp | 38 ++++++++
3rdparty/stout/include/stout/os/xattr.hpp | 26 +++++
5 files changed, 167 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e3c12c4c/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 1eb9c14..d5bc728 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -104,6 +104,7 @@ nobase_include_HEADERS = \
stout/os/utime.hpp \
stout/os/wait.hpp \
stout/os/write.hpp \
+ stout/os/xattr.hpp \
stout/os/posix/bootid.hpp \
stout/os/posix/chown.hpp \
stout/os/posix/chroot.hpp \
@@ -128,6 +129,7 @@ nobase_include_HEADERS = \
stout/os/posix/stat.hpp \
stout/os/posix/su.hpp \
stout/os/posix/write.hpp \
+ stout/os/posix/xattr.hpp \
stout/os/raw/argv.hpp \
stout/os/raw/environment.hpp \
stout/os/windows/bootid.hpp \
@@ -153,6 +155,7 @@ nobase_include_HEADERS = \
stout/os/windows/stat.hpp \
stout/os/windows/su.hpp \
stout/os/windows/write.hpp \
+ stout/os/windows/xattr.hpp \
stout/path.hpp \
stout/preprocessor.hpp \
stout/proc.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/e3c12c4c/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os.hpp b/3rdparty/stout/include/stout/os.hpp
index 96e8621..af43bbf 100644
--- a/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/stout/include/stout/os.hpp
@@ -64,6 +64,7 @@
#include <stout/os/touch.hpp>
#include <stout/os/utime.hpp>
#include <stout/os/wait.hpp>
+#include <stout/os/xattr.hpp>
#include <stout/os/raw/argv.hpp>
#include <stout/os/raw/environment.hpp>
http://git-wip-us.apache.org/repos/asf/mesos/blob/e3c12c4c/3rdparty/stout/include/stout/os/posix/xattr.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/xattr.hpp b/3rdparty/stout/include/stout/os/posix/xattr.hpp
new file mode 100644
index 0000000..518940f
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/xattr.hpp
@@ -0,0 +1,99 @@
+// 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_XATTR_HPP__
+#define __STOUT_OS_POSIX_XATTR_HPP__
+
+#include <sys/xattr.h>
+
+namespace os {
+
+inline Try<Nothing> setxattr(
+ const std::string& path,
+ const std::string& name,
+ const std::string& value,
+ int flags)
+{
+#ifdef __APPLE__
+ if (::setxattr(
+ path.c_str(),
+ name.c_str(),
+ value.c_str(),
+ value.length(),
+ 0,
+ flags) < 0) {
+#else
+ if (::setxattr(
+ path.c_str(),
+ name.c_str(),
+ value.c_str(),
+ value.length(),
+ flags) < 0) {
+#endif
+ return ErrnoError();
+ }
+
+ return Nothing();
+}
+
+
+inline Try<std::string> getxattr(
+ const std::string& path,
+ const std::string& name)
+{
+ // Get the current size of the attribute.
+#ifdef __APPLE__
+ ssize_t size = ::getxattr(path.c_str(), name.c_str(), nullptr, 0, 0, 0);
+#else
+ ssize_t size = ::getxattr(path.c_str(), name.c_str(), nullptr, 0);
+#endif
+ if (size < 0) {
+ return ErrnoError();
+ }
+
+ char* temp = new char[size + 1];
+ ::memset(temp, 0, (size_t)size + 1);
+
+#ifdef __APPLE__
+ if (::getxattr(path.c_str(), name.c_str(), temp, (size_t)size, 0, 0) < 0) {
+#else
+ if (::getxattr(path.c_str(), name.c_str(), temp, (size_t)size) < 0) {
+#endif
+ delete[] temp;
+ return ErrnoError();
+ }
+
+ std::string result(temp);
+ delete[] temp;
+
+ return result;
+}
+
+
+inline Try<Nothing> removexattr(
+ const std::string& path,
+ const std::string& name)
+{
+#ifdef __APPLE__
+ if (::removexattr(path.c_str(), name.c_str(), 0) < 0) {
+#else
+ if (::removexattr(path.c_str(), name.c_str()) < 0) {
+#endif
+ return ErrnoError();
+ }
+
+ return Nothing();
+}
+
+} // namespace os {
+
+#endif /* __STOUT_OS_POSIX_XATTR_HPP__ */
http://git-wip-us.apache.org/repos/asf/mesos/blob/e3c12c4c/3rdparty/stout/include/stout/os/windows/xattr.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/xattr.hpp b/3rdparty/stout/include/stout/os/windows/xattr.hpp
new file mode 100644
index 0000000..3157f72
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/xattr.hpp
@@ -0,0 +1,38 @@
+// 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_XATTR_HPP__
+#define __STOUT_OS_WINDOWS_XATTR_HPP__
+
+namespace os {
+
+// NOTE: These functions are deleted because Windows does
+// not support POSIX extended attribute semantics.
+inline Try<Nothing> setxattr(
+ const std::string& path,
+ const std::string& name,
+ const std::string& value,
+ int flags) = delete;
+
+
+inline Try<std::string> getxattr(
+ const std::string& path,
+ const std::string& name) = delete;
+
+
+inline Try<std::string> removexattr(
+ const std::string& path,
+ const std::string& name) = delete;
+
+} // namespace os {
+
+#endif /* __STOUT_OS_WINDOWS_XATTR_HPP__ */
http://git-wip-us.apache.org/repos/asf/mesos/blob/e3c12c4c/3rdparty/stout/include/stout/os/xattr.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/xattr.hpp b/3rdparty/stout/include/stout/os/xattr.hpp
new file mode 100644
index 0000000..b86b50a
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/xattr.hpp
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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_XATTR_HPP__
+#define __STOUT_OS_XATTR_HPP__
+
+#ifdef __WINDOWS__
+#include <stout/os/windows/xattr.hpp>
+#else
+#include <stout/os/posix/xattr.hpp>
+#endif // __WINDOWS__
+
+#endif // __STOUT_OS_XATTR_HPP__