about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2007-08-21 22:59:48 +0000
committerClint Adams <clint@users.sourceforge.net>2007-08-21 22:59:48 +0000
commit4cff29774e018733b4857b89326855d222e068a0 (patch)
tree56c53b1220fa495656eca4f9a51201c4c869f42f /Src
parent10ad489ff08eb897b05cf0ff5f0458b19a32c1aa (diff)
downloadzsh-4cff29774e018733b4857b89326855d222e068a0.tar.gz
zsh-4cff29774e018733b4857b89326855d222e068a0.tar.xz
zsh-4cff29774e018733b4857b89326855d222e068a0.zip
23788: add -h option to chown symlinks rather than targets, and change default behavior to do the opposite.
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/files.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 0ce6d78d0..db4d74de0 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -593,6 +593,19 @@ chown_dochown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
 {
     struct chownmagic *chm = magic;
 
+    if(chown(rp, chm->uid, chm->gid)) {
+	zwarnnam(chm->nam, "%s: %e", arg, errno);
+	return 1;
+    }
+    return 0;
+}
+
+/**/
+static int
+chown_dolchown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
+{
+    struct chownmagic *chm = magic;
+
     if(lchown(rp, chm->uid, chm->gid)) {
 	zwarnnam(chm->nam, "%s: %e", arg, errno);
 	return 1;
@@ -600,6 +613,7 @@ chown_dochown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
     return 0;
 }
 
+
 /**/
 static unsigned long getnumeric(char *p, int *errp)
 {
@@ -684,7 +698,8 @@ bin_chown(char *nam, char **args, Options ops, int func)
     }
     free(uspec);
     return recursivecmd(nam, 0, OPT_ISSET(ops,'R'), OPT_ISSET(ops,'s'),
-	args + 1, chown_dochown, recurse_donothing, chown_dochown, &chm);
+	args + 1, OPT_ISSET(ops, 'h') ? chown_dolchown : chown_dochown, recurse_donothing,
+	OPT_ISSET(ops, 'h') ? chown_dolchown : chown_dochown, &chm);
 }
 
 /* module paraphernalia */
@@ -696,8 +711,8 @@ bin_chown(char *nam, char **args, Options ops, int func)
 #endif
 
 static struct builtin bintab[] = {
-    BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "Rs",    NULL),
-    BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "Rs",    NULL),
+    BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "hRs",    NULL),
+    BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "hRs",    NULL),
     BUILTIN("ln",    0, bin_ln,    1, -1, BIN_LN,    LN_OPTS, NULL),
     BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0,         "pm:",   NULL),
     BUILTIN("mv",    0, bin_ln,    2, -1, BIN_MV,    "fi",    NULL),