Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 1/4] attr: add -h option to operate on symlinks without dereferencing
- X-seq: zsh-workers 27343
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: [PATCH 1/4] attr: add -h option to operate on symlinks without dereferencing
- Date: Tue, 3 Nov 2009 19:55:33 +0100 (CET)
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :in-reply-to:message-id:references:user-agent:mime-version :content-type; bh=HWLZIOgUize+tXYCwKF3+xaLax0k6u3pXfQpLMqabYM=; b=aBSvANVe1lo/31kC+3+dB4Z7QN9hecb0vxwK/l+veST96kW0Hxm/neFU78SFJs64wN 2uybK7LMB447FDtrjHwc9wxDFRipTseXlmr+fBlnPiBxN0smnK0mUaEPOKLQrdYJ/X4F w5At2K7uvLOHhLf/UwgviO8QxyGlrG4SP8rtA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:in-reply-to:message-id:references:user-agent :mime-version:content-type; b=P+yPJZaJ5I69Lzp1a0vtpuYyeKDEF+NjjJXdb3tmhA2g8/FK6GXuAsQmQaXwHKzKS0 mk5HsUADvw0khdz7sJLpDcFMoznMNl1rLy8tlShUnJGZeW/I1SfSgvYDltiAwnUmBCa2 mwzofw5cXyFIy1QCi5kdM7aMp2PqggPQJ5mz4=
- In-reply-to: <alpine.LNX.2.00.0911031951480.3519@localhost>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <alpine.LNX.2.00.0902262245590.27571@localhost> <20090303121253.61f5e2ec@news01> <alpine.LNX.2.00.0903031455360.10365@localhost> <20090303163526.533995be@news01> <237967ef0903030851gc26620ficfc908628a4b3be2@xxxxxxxxxxxxxx> <alpine.LNX.2.00.0911031951480.3519@localhost>
Since the OSX-style interface doesn't have the l* family, make wrapper
functions that handle the boring details.
---
Src/Modules/attr.c | 111 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 78 insertions(+), 33 deletions(-)
diff --git a/Src/Modules/attr.c b/Src/Modules/attr.c
index ec3b1e4..cbf3d92 100644
--- a/Src/Modules/attr.c
+++ b/Src/Modules/attr.c
@@ -33,25 +33,79 @@
#include <sys/types.h>
#include <sys/xattr.h>
+static ssize_t
+xgetxattr(const char *path, const char *name, void *value, size_t size, int symlink)
+{
+#ifdef XATTR_EXTRA_ARGS
+ return getxattr(path, name, value, size, 0, symlink ? XATTR_NOFOLLOW: 0);
+#else
+ switch (symlink) {
+ case 0:
+ return getxattr(path, name, value, size);
+ case 1:
+ return lgetxattr(path, name, value, size);
+ }
+#endif
+}
+
+static ssize_t
+xlistxattr(const char *path, char *list, size_t size, int symlink)
+{
+#ifdef XATTR_EXTRA_ARGS
+ return listxattr(path, list, size, symlink ? XATTR_NOFOLLOW : 0);
+#else
+ switch (symlink) {
+ case 0:
+ return listxattr(path, list, size);
+ case 1:
+ return llistxattr(path, list, size);
+ }
+#endif
+}
+
+static int
+xsetxattr(const char *path, const char *name, const void *value,
+ size_t size, int flags, int symlink)
+{
+#ifdef XATTR_EXTRA_ARGS
+ return setxattr(path, name, value, size, 0, flags | symlink ? XATTR_NOFOLLOW : 0);
+#else
+ switch (symlink) {
+ case 0:
+ return setxattr(path, name, value, size, flags);
+ case 1:
+ return lsetxattr(path, name, value, size, flags);
+ }
+#endif
+}
+
static int
-bin_getattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
+xremovexattr(const char *path, const char *name, int symlink)
+{
+#ifdef XATTR_EXTRA_ARGS
+ return removexattr(path, name, symlink ? XATTR_NOFOLLOW : 0);
+#else
+ switch (symlink) {
+ case 0:
+ return removexattr(path, name);
+ case 1:
+ return lremovexattr(path, name);
+ }
+#endif
+}
+
+static int
+bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0;
int len, slen;
char value[256];
+ int symlink = OPT_ISSET(ops, 'h');
unmetafy(*argv, &slen);
unmetafy(*(argv+1), NULL);
- if (listxattr(*argv, NULL, 0
-#ifdef XATTR_EXTRA_ARGS
- , 0
-#endif
- ) > 0) {
- if (0 < (len = getxattr(*argv, *(argv+1), value, 255
-#ifdef XATTR_EXTRA_ARGS
- , 0, 0
-#endif
- ))) {
+ if (xlistxattr(*argv, NULL, 0, symlink) > 0) {
+ if (0 < (len = xgetxattr(*argv, *(argv+1), value, 255, symlink))) {
if (len < 256) {
value[len] = '\0';
if (*(argv+2))
@@ -68,18 +122,15 @@ bin_getattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
}
static int
-bin_setattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
+bin_setattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0, slen;
+ int symlink = OPT_ISSET(ops, 'h');
unmetafy(*argv, &slen);
unmetafy(*(argv+1), NULL);
unmetafy(*(argv+2), NULL);
- if (setxattr(*argv, *(argv+1), *(argv+2), strlen(*(argv+2)), 0
-#ifdef XATTR_EXTRA_ARGS
- , 0
-#endif
- )) {
+ if (xsetxattr(*argv, *(argv+1), *(argv+2), strlen(*(argv+2)), 0, symlink)) {
zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno);
ret = 1;
}
@@ -87,17 +138,14 @@ bin_setattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
}
static int
-bin_delattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
+bin_delattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0, slen;
+ int symlink = OPT_ISSET(ops, 'h');
unmetafy(*argv, &slen);
unmetafy(*(argv+1), NULL);
- if (removexattr(*argv, *(argv+1)
-#ifdef XATTR_EXTRA_ARGS
- , 0
-#endif
- )) {
+ if (xremovexattr(*argv, *(argv+1), symlink)) {
zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno);
ret = 1;
}
@@ -105,18 +153,15 @@ bin_delattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
}
static int
-bin_listattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
+bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0;
int len, slen;
char value[256];
+ int symlink = OPT_ISSET(ops, 'h');
unmetafy(*argv, &slen);
- if (0 < (len = listxattr(*argv, value, 256
-#ifdef XATTR_EXTRA_ARGS
- , 0
-#endif
- ))) {
+ if (0 < (len = xlistxattr(*argv, value, 256, symlink))) {
if (len < 256) {
char *p = value;
if (*(argv+1))
@@ -136,10 +181,10 @@ bin_listattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
/* module paraphernalia */
static struct builtin bintab[] = {
- BUILTIN("zgetattr", 0, bin_getattr, 2, 3, 0, NULL, NULL),
- BUILTIN("zsetattr", 0, bin_setattr, 3, 3, 0, NULL, NULL),
- BUILTIN("zdelattr", 0, bin_delattr, 2, 2, 0, NULL, NULL),
- BUILTIN("zlistattr", 0, bin_listattr, 1, 2, 0, NULL, NULL),
+ BUILTIN("zgetattr", 0, bin_getattr, 2, 3, 0, "h", NULL),
+ BUILTIN("zsetattr", 0, bin_setattr, 3, 3, 0, "h", NULL),
+ BUILTIN("zdelattr", 0, bin_delattr, 2, 2, 0, "h", NULL),
+ BUILTIN("zlistattr", 0, bin_listattr, 1, 2, 0, "h", NULL),
};
static struct features module_features = {
--
1.6.5
Messages sorted by:
Reverse Date,
Date,
Thread,
Author