diff options
author | Bob Ippolito <bob@redivi.com> | 2012-01-23 09:25:18 -0800 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2012-01-23 09:25:18 -0800 |
commit | 2566746c4c29b143a32da2ce68e48f949f7a9a92 (patch) | |
tree | e83f8a27fe716b91468707942aebe6225acfdc11 | |
parent | 60e8bea98c5a3b0ed0e43f5a1043c22741ab5955 (diff) | |
parent | d9a4ab87aca1d9484fe89085bf310591171412d8 (diff) | |
download | xattr-2566746c4c29b143a32da2ce68e48f949f7a9a92.tar.gz |
Merge remote-tracking branch 'gfxmonk/allow_xattr_on_symlinks'
-rw-r--r-- | xattr/_xattr.c | 6 | ||||
-rw-r--r-- | xattr/tests/test_xattr.py | 41 |
2 files changed, 30 insertions, 17 deletions
diff --git a/xattr/_xattr.c b/xattr/_xattr.c index 630ec1d..ca794ee 100644 --- a/xattr/_xattr.c +++ b/xattr/_xattr.c @@ -80,7 +80,7 @@ static ssize_t xattr_setxattr(const char *path, const char *name, return -1; } - if (options & XATTR_XATTR_NOFOLLOW) { + if (nofollow) { rv = extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, value, size); } @@ -175,7 +175,7 @@ static ssize_t xattr_fsetxattr(int fd, const char *name, void *value, return -1; } - if (options & XATTR_XATTR_NOFOLLOW) { + if (nofollow) { return -1; } else { @@ -447,7 +447,7 @@ static ssize_t xattr_setxattr(const char *path, const char *name, void *value, s } else if (options != 0) { return -1; } - if (options & XATTR_XATTR_NOFOLLOW) { + if (nofollow) { return lsetxattr(path, name, value, size, options); } else { return setxattr(path, name, value, size, options); diff --git a/xattr/tests/test_xattr.py b/xattr/tests/test_xattr.py index 8c6c467..0124fef 100644 --- a/xattr/tests/test_xattr.py +++ b/xattr/tests/test_xattr.py @@ -1,42 +1,55 @@ import os from unittest import TestCase -from tempfile import mkstemp, mkdtemp +from tempfile import mkdtemp, NamedTemporaryFile +from os import tempnam import xattr class TestFile(TestCase): def setUp(self): - self.tempfh, self.tempfile = mkstemp() + self.tempfile = NamedTemporaryFile() + self.tempfilename = self.tempfile.name def tearDown(self): - os.close(self.tempfh) - os.unlink(self.tempfile) + self.tempfile.close() def testAttr(self): x = xattr.xattr(self.tempfile) self.assertEqual(x.keys(), []) self.assertEqual(dict(x), {}) - x['sopal'] = 'foo' - x['sop.foo'] = 'bar' + x['user.sopal'] = 'foo' + x['user.sop.foo'] = 'bar' del x x = xattr.xattr(self.tempfile) - self.assertTrue('sopal' in x) - self.assertEqual(x['sopal'], 'foo') - self.assertTrue('sop.foo' in x) - self.assertEqual(x['sop.foo'], 'bar') + self.assertTrue('user.sopal' in x) + self.assertEqual(x['user.sopal'], 'foo') + self.assertTrue('user.sop.foo' in x) + self.assertEqual(x['user.sop.foo'], 'bar') - del x['sop.foo'] + del x['user.sop.foo'] del x x = xattr.xattr(self.tempfile) - self.assertTrue('sop.foo' not in x) - + self.assertTrue('user.sop.foo' not in x) + + def testSymlinkAttrs(self): + symlinkPath = tempnam() + os.symlink(self.tempfilename, symlinkPath) + try: + symlink = xattr.xattr(symlinkPath, options=xattr.XATTR_NOFOLLOW) + realfile = xattr.xattr(self.tempfilename) + symlink['user.islink'] = 'true' + self.assertEqual(dict(realfile), {}) + self.assertEqual(symlink['user.islink'], 'true') + finally: + os.remove(symlinkPath) class TestDir(TestFile): def setUp(self): self.tempfile = mkdtemp() + self.tempfilename = self.tempfile def tearDown(self): - os.rmdir(self.tempfile)
\ No newline at end of file + os.rmdir(self.tempfile) |