From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29871 invoked by alias); 6 Nov 2014 15:13:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33607 Received: (qmail 28134 invoked from network); 6 Nov 2014 15:13:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=+y8U2You4HVdSHoBqOWDATlS29d8jkLMOjpibxDJgk8=; b=j7dbrx+yuulu1tnwr5yjxMZGMC1ZOC4TMnojupyfv+sVDPrloOwED5fm0fSEzZOxCw mCmPXeN5NMhZnZOgq+yIsXs7WYGT2Pw8wTm6mMQMZX2/JkNZKB0FhhGIGnJmHkrN0PEW A9/hJzBufvFD3FhX7ajyNGbvhQj4Uzx7tL48ciwB9CZhwb5o9bTVKjFB/y4dmtfJKnbK pp0haJsYmy5bjiEqwyT7+FAwLBFqIXiFgPtCO+sAAyk/EXphqr6me828sVZ1EyyXN6kL vBgp8xOrWtZ/sqK9EdmPzAgmlpZ13/uV3/X9phNbGLIfikLGjxRAgkGGgoB++/yHlX+W j7bA== X-Received: by 10.194.92.148 with SMTP id cm20mr5546372wjb.88.1415286819488; Thu, 06 Nov 2014 07:13:39 -0800 (PST) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Fix some minor problems in zattr module Date: Thu, 6 Nov 2014 16:13:32 +0100 Message-Id: <1415286812-15462-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.2.0-rc0 Remove the listattr call in zgetattr, it only caused no error to be output when trying to retrieve an xattr from a file with no xattrs. When a file had xattrs, it would just add an extra syscall for no good reason. Always set an array parameter in zlistattr, this makes the returned value much easier to use; in fact the _zattr completer didn't account for this and zlistattr foo on a file with only one attribute did not work. Almost all of the patch is only reindent, the only modification that's not a pure deletions is: - ret = 1 + (attr_len > val_len || attr_len < 0); + ret = 1 + ((val_len > 0 && attr_len > val_len) || attr_len < 0); which makes sure we return the correct error in the new path due to the removed listattr call. (If val_len is -1 due to no attribute existing, it doesn't mean the user should retry the call because the attribute grew in size). --- Src/Modules/attr.c | 67 ++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/Src/Modules/attr.c b/Src/Modules/attr.c index 6e08b10..78c1104 100644 --- a/Src/Modules/attr.c +++ b/Src/Modules/attr.c @@ -98,36 +98,33 @@ static int bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func)) { int ret = 0; - int list_len, val_len = 0, attr_len = 0, slen; + int val_len = 0, attr_len = 0, slen; char *value, *file = argv[0], *attr = argv[1], *param = argv[2]; int symlink = OPT_ISSET(ops, 'h'); unmetafy(file, &slen); unmetafy(attr, NULL); - list_len = xlistxattr(file, NULL, 0, symlink); - if (list_len > 0) { - val_len = xgetxattr(file, attr, NULL, 0, symlink); - if (val_len == 0) { + val_len = xgetxattr(file, attr, NULL, 0, symlink); + if (val_len == 0) { + if (param) + unsetparam(param); + return 0; + } + if (val_len > 0) { + value = (char *)zalloc(val_len+1); + attr_len = xgetxattr(file, attr, value, val_len, symlink); + if (attr_len > 0 && attr_len <= val_len) { + value[attr_len] = '\0'; if (param) - unsetparam(param); - return 0; - } - if (val_len > 0) { - value = (char *)zalloc(val_len+1); - attr_len = xgetxattr(file, attr, value, val_len, symlink); - if (attr_len > 0 && attr_len <= val_len) { - value[attr_len] = '\0'; - if (param) - setsparam(param, metafy(value, attr_len, META_DUP)); - else - printf("%s\n", value); - } - zfree(value, val_len+1); + setsparam(param, metafy(value, attr_len, META_DUP)); + else + printf("%s\n", value); } + zfree(value, val_len+1); } - if (list_len < 0 || val_len < 0 || attr_len < 0 || attr_len > val_len) { + if (val_len < 0 || attr_len < 0 || attr_len > val_len) { zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno); - ret = 1 + (attr_len > val_len || attr_len < 0); + ret = 1 + ((val_len > 0 && attr_len > val_len) || attr_len < 0); } return ret; } @@ -189,24 +186,20 @@ bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func)) if (list_len > 0 && list_len <= val_len) { char *p = value; if (param) { - if (strlen(value) + 1 == list_len) - setsparam(param, metafy(value, list_len-1, META_DUP)); - else { - int arrlen = 0; - char **array = NULL, **arrptr = NULL; + int arrlen = 0; + char **array = NULL, **arrptr = NULL; - while (p < &value[list_len]) { - arrlen++; - p += strlen(p) + 1; - } - arrptr = array = (char **)zshcalloc((arrlen+1) * sizeof(char *)); - p = value; - while (p < &value[list_len]) { - *arrptr++ = metafy(p, -1, META_DUP); - p += strlen(p) + 1; - } - setaparam(param, array); + while (p < &value[list_len]) { + arrlen++; + p += strlen(p) + 1; + } + arrptr = array = (char **)zshcalloc((arrlen+1) * sizeof(char *)); + p = value; + while (p < &value[list_len]) { + *arrptr++ = metafy(p, -1, META_DUP); + p += strlen(p) + 1; } + setaparam(param, array); } else while (p < &value[list_len]) { printf("%s\n", p); p += strlen(p) + 1; -- 2.2.0-rc0