1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-25 17:41:19 +02:00

Merge of 23788: add -h option to chown symlinks rather than targets, and change default behavior to do the opposite.

This commit is contained in:
Paul Ackersviller 2007-11-25 00:47:32 +00:00
parent 4ecf5b41ea
commit 4ad8baffe9
2 changed files with 23 additions and 5 deletions

View file

@ -6,12 +6,12 @@ The tt(zsh/files) module makes some standard commands available as builtins:
startitem() startitem()
findex(chgrp) findex(chgrp)
item(tt(chgrp) [ tt(-Rs) ] var(group) var(filename) ...)( item(tt(chgrp) [ tt(-hRs) ] var(group) var(filename) ...)(
Changes group of files specified. This is equivalent to tt(chown) with Changes group of files specified. This is equivalent to tt(chown) with
a var(user-spec) argument of `tt(:)var(group)'. a var(user-spec) argument of `tt(:)var(group)'.
) )
findex(chown) findex(chown)
item(tt(chown) [ tt(-Rs) ] var(user-spec) var(filename) ...)( item(tt(chown) [ tt(-hRs) ] var(user-spec) var(filename) ...)(
Changes ownership and group of files specified. Changes ownership and group of files specified.
The var(user-spec) can be in four forms: The var(user-spec) can be in four forms:
@ -33,6 +33,9 @@ Each of var(user) and var(group) may be either a username (or group name, as
appropriate) or a decimal user ID (group ID). Interpretation as a name appropriate) or a decimal user ID (group ID). Interpretation as a name
takes precedence, if there is an all-numeric username (or group name). takes precedence, if there is an all-numeric username (or group name).
If the target is a symbolic link, the tt(-h) option causes tt(chown) to set
the ownership of the link instead of its target.
The tt(-R) option causes tt(chown) to recursively descend into directories, The tt(-R) option causes tt(chown) to recursively descend into directories,
changing the ownership of all files in the directory after changing the ownership of all files in the directory after
changing the ownership of the directory itself. changing the ownership of the directory itself.

View file

@ -593,6 +593,19 @@ chown_dochown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
{ {
struct chownmagic *chm = 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)) { if(lchown(rp, chm->uid, chm->gid)) {
zwarnnam(chm->nam, "%s: %e", arg, errno); zwarnnam(chm->nam, "%s: %e", arg, errno);
return 1; return 1;
@ -600,6 +613,7 @@ chown_dochown(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
return 0; return 0;
} }
/**/ /**/
static unsigned long getnumeric(char *p, int *errp) static unsigned long getnumeric(char *p, int *errp)
{ {
@ -684,7 +698,8 @@ bin_chown(char *nam, char **args, Options ops, int func)
} }
free(uspec); free(uspec);
return recursivecmd(nam, 0, OPT_ISSET(ops,'R'), OPT_ISSET(ops,'s'), 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 */ /* module paraphernalia */
@ -696,8 +711,8 @@ bin_chown(char *nam, char **args, Options ops, int func)
#endif #endif
static struct builtin bintab[] = { static struct builtin bintab[] = {
BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "Rs", NULL), BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "hRs", NULL),
BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "Rs", 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("ln", 0, bin_ln, 1, -1, BIN_LN, LN_OPTS, NULL),
BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0, "pm:", NULL), BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0, "pm:", NULL),
BUILTIN("mv", 0, bin_ln, 2, -1, BIN_MV, "fi", NULL), BUILTIN("mv", 0, bin_ln, 2, -1, BIN_MV, "fi", NULL),