summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2014-03-27 08:31:43 -0700
committerBob Ippolito <bob@redivi.com>2014-03-27 08:31:43 -0700
commit70d1ad2caf11e8dbdef9bc0dcdd2c3702d70b607 (patch)
treee27dc225621826966bf028844429a66e68e64ede
parent81592ca1b24f73e9e28c06a0923ddf396d2ac3e4 (diff)
parentfed2d4f7d40cc561b577ff04395c994201500491 (diff)
downloadxattr-70d1ad2caf11e8dbdef9bc0dcdd2c3702d70b607.tar.gz
Merge pull request #29 from dhduvall/master
bug 28: solaris & solaris studio compiler support
-rw-r--r--xattr/lib.py16
-rw-r--r--xattr/tests/test_xattr.py28
2 files changed, 33 insertions, 11 deletions
diff --git a/xattr/lib.py b/xattr/lib.py
index a8a5d80..52b48ed 100644
--- a/xattr/lib.py
+++ b/xattr/lib.py
@@ -29,12 +29,13 @@ lib = ffi.verify("""
#include "Python.h"
#ifdef __FreeBSD__
#include <sys/extattr.h>
-#elif defined(__SUN__) || defined(__sun__) || defined(sun)
+#elif defined(__SUN__) || defined(__sun__) || defined(__sun)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#include <alloca.h>
#else
#include <sys/xattr.h>
#endif
@@ -59,7 +60,7 @@ static void convert_bsd_list(char *namebuf, size_t size)
while(offset < size) {
int length = (int) namebuf[offset];
memmove(namebuf+offset, namebuf+offset+1, length);
- namebuf[offset+length] = '\0';
+ namebuf[offset+length] = '\\0';
offset += length+1;
}
}
@@ -260,7 +261,7 @@ static ssize_t xattr_flistxattr(int fd, char *namebuf, size_t size, int options)
return rv;
}
-#elif defined(__SUN__) || defined(__sun__) || defined(sun)
+#elif defined(__SUN__) || defined(__sun__) || defined(__sun)
/* Solaris 9 and later compatibility API */
#define XATTR_XATTR_NOFOLLOW 0x0001
@@ -268,6 +269,9 @@ static ssize_t xattr_flistxattr(int fd, char *namebuf, size_t size, int options)
#define XATTR_XATTR_REPLACE 0x0004
#define XATTR_XATTR_NOSECURITY 0x0008
+#define XATTR_CREATE 0x1
+#define XATTR_REPLACE 0x2
+
#ifndef u_int32_t
#define u_int32_t uint32_t
#endif
@@ -429,7 +433,7 @@ static ssize_t xattr_xflistxattr(int xfd, char *namebuf, size_t size, int option
snprintf((char *)(namebuf + nsize), esize + 1,
entry->d_name);
}
- nsize += esize + 1; /* +1 for \0 */
+ nsize += esize + 1; /* +1 for \\0 */
}
closedir(dirp);
return nsize;
@@ -438,7 +442,7 @@ static ssize_t xattr_flistxattr(int fd, char *namebuf, size_t size, int options)
{
int xfd;
- xfd = openat(fd, ".", O_RDONLY);
+ xfd = openat(fd, ".", O_RDONLY | O_XATTR);
return xattr_xflistxattr(xfd, namebuf, size, options);
}
@@ -725,7 +729,7 @@ def _flistxattr(fd, options=0):
flistxattr(fd, options=0) -> str
"""
res = lib.xattr_flistxattr(fd, ffi.NULL, 0, options)
- if res == 1:
+ if res == -1:
raise error()
buf = ffi.new("char[]", res)
res = lib.xattr_flistxattr(fd, buf, res, options)
diff --git a/xattr/tests/test_xattr.py b/xattr/tests/test_xattr.py
index b02cb81..bd201b7 100644
--- a/xattr/tests/test_xattr.py
+++ b/xattr/tests/test_xattr.py
@@ -9,9 +9,18 @@ import xattr
class BaseTestXattr(object):
def test_attr(self):
x = xattr.xattr(self.tempfile)
- self.assertEqual(x.keys(), [])
- self.assertEqual(x.list(), [])
- self.assertEqual(dict(x), {})
+
+ # Solaris 11 and forward contain system attributes (file flags) in
+ # extended attributes present on all files, so cons them up into a
+ # comparison dict.
+ d = {}
+ if sys.platform == 'sunos5' and 'SUNWattr_ro' in x:
+ d['SUNWattr_ro'] = x['SUNWattr_ro']
+ d['SUNWattr_rw'] = x['SUNWattr_rw']
+
+ self.assertEqual(x.keys(), d.keys())
+ self.assertEqual(x.list(), d.keys())
+ self.assertEqual(dict(x), d)
x['user.sopal'] = b'foo'
x['user.sop.foo'] = b'bar'
@@ -40,15 +49,24 @@ class BaseTestXattr(object):
def test_setxattr_unicode_error(self):
x = xattr.xattr(self.tempfile)
- with self.assertRaises(TypeError) as exc_info:
+ def assign():
x['abc'] = u'abc'
+ self.assertRaises(TypeError, assign)
+
if sys.version_info[0] >= 3:
msg = "Value must be bytes, str was passed."
else:
msg = "Value must be bytes, unicode was passed."
- self.assertEqual(str(exc_info.exception), msg)
+
+ try:
+ assign()
+ except TypeError, e:
+ self.assertEqual(str(e), msg)
def test_symlink_attrs(self):
+ # Solaris doesn't support extended attributes on symlinks
+ if sys.platform == 'sunos5':
+ return
symlinkPath = self.tempfilename + '.link'
os.symlink(self.tempfilename, symlinkPath)
try: