aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/native
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2018-02-09 10:19:29 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-09 10:20:51 -0800
commitad32f62952e2b6f8293a26ea5fd677e61975c9ff (patch)
treef5036251b75b6822fba34fce5ac2fa6425e5383e /src/main/native
parent8cc1706ac8e9751e347720054ede3a3d88385c88 (diff)
Make getxattr not throw an exception when attribute does not exist on Mac.
This matches the current behavior on Linux. When an extended attribute is not present on a file, getxattr on Linux returns ENODATA whereas getxattr on Mac returns ENOATTR. Previously, we were special casing ENODATA to not throw an exception but not ENOATTR. Now we treat them the same. RELNOTES: None PiperOrigin-RevId: 185157964
Diffstat (limited to 'src/main/native')
-rw-r--r--src/main/native/unix_jni.cc8
-rw-r--r--src/main/native/unix_jni.h12
-rw-r--r--src/main/native/unix_jni_darwin.cc12
-rw-r--r--src/main/native/unix_jni_linux.cc12
4 files changed, 29 insertions, 15 deletions
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc
index 7615c67da4..98686af349 100644
--- a/src/main/native/unix_jni.cc
+++ b/src/main/native/unix_jni.cc
@@ -847,7 +847,7 @@ Java_com_google_devtools_build_lib_unix_NativePosixFiles_mkfifo(JNIEnv *env,
// Linux extended file attributes
typedef ssize_t getxattr_func(const char *path, const char *name,
- void *value, size_t size);
+ void *value, size_t size, bool *attr_not_found);
static jbyteArray getxattr_common(JNIEnv *env,
jstring path,
@@ -859,9 +859,11 @@ static jbyteArray getxattr_common(JNIEnv *env,
// TODO(bazel-team): on ERANGE, try again with larger buffer.
jbyte value[4096];
jbyteArray result = NULL;
- ssize_t size = getxattr(path_chars, name_chars, value, arraysize(value));
+ bool attr_not_found = false;
+ ssize_t size = getxattr(path_chars, name_chars, value, arraysize(value),
+ &attr_not_found);
if (size == -1) {
- if (errno != ENODATA) {
+ if (!attr_not_found) {
::PostFileException(env, errno, path_chars);
}
} else {
diff --git a/src/main/native/unix_jni.h b/src/main/native/unix_jni.h
index f4a1600161..19d5b3f1f8 100644
--- a/src/main/native/unix_jni.h
+++ b/src/main/native/unix_jni.h
@@ -83,13 +83,17 @@ int StatSeconds(const portable_stat_struct &statbuf, StatTimes t);
// Returns nanoseconds from a stat buffer.
int StatNanoSeconds(const portable_stat_struct &statbuf, StatTimes t);
-// Runs getxattr(2), if available. If not, sets errno to ENOSYS.
+// Runs getxattr(2). If the attribute is not found, returns -1 and sets
+// attr_not_found to true. For all other errors, returns -1, sets attr_not_found
+// to false and leaves errno set to the error code returned by the system.
ssize_t portable_getxattr(const char *path, const char *name, void *value,
- size_t size);
+ size_t size, bool *attr_not_found);
-// Run lgetxattr(2), if available. If not, sets errno to ENOSYS.
+// Runs lgetxattr(2). If the attribute is not found, returns -1 and sets
+// attr_not_found to true. For all other errors, returns -1, sets attr_not_found
+// to false and leaves errno set to the error code returned by the system.
ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
- size_t size);
+ size_t size, bool *attr_not_found);
// Run sysctlbyname(3), only available on darwin
int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep);
diff --git a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc
index 02aaa98a7f..06fbf443c9 100644
--- a/src/main/native/unix_jni_darwin.cc
+++ b/src/main/native/unix_jni_darwin.cc
@@ -104,13 +104,17 @@ int StatNanoSeconds(const portable_stat_struct &statbuf, StatTimes t) {
}
ssize_t portable_getxattr(const char *path, const char *name, void *value,
- size_t size) {
- return getxattr(path, name, value, size, 0, 0);
+ size_t size, bool *attr_not_found) {
+ ssize_t result = getxattr(path, name, value, size, 0, 0);
+ *attr_not_found = (errno == ENOATTR);
+ return result;
}
ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
- size_t size) {
- return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
+ size_t size, bool *attr_not_found) {
+ ssize_t result = getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
+ *attr_not_found = (errno == ENOATTR);
+ return result;
}
int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) {
diff --git a/src/main/native/unix_jni_linux.cc b/src/main/native/unix_jni_linux.cc
index 772b400716..f66de383f1 100644
--- a/src/main/native/unix_jni_linux.cc
+++ b/src/main/native/unix_jni_linux.cc
@@ -74,13 +74,17 @@ int StatNanoSeconds(const portable_stat_struct &statbuf, StatTimes t) {
}
ssize_t portable_getxattr(const char *path, const char *name, void *value,
- size_t size) {
- return ::getxattr(path, name, value, size);
+ size_t size, bool *attr_not_found) {
+ ssize_t result = ::getxattr(path, name, value, size);
+ *attr_not_found = (errno == ENODATA);
+ return result;
}
ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
- size_t size) {
- return ::lgetxattr(path, name, value, size);
+ size_t size, bool *attr_not_found) {
+ ssize_t result = ::lgetxattr(path, name, value, size);
+ *attr_not_found = (errno == ENODATA);
+ return result;
}
int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) {