Implemented -find actions chown_r, chgrp_r, chmod_r, alter_date_r, find

This commit is contained in:
Thomas Schmitt 2008-01-01 12:32:23 +00:00
parent 4b25b22ded
commit 5373244892
7 changed files with 256 additions and 72 deletions

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "December 31, 2007"
.TH XORRISO 1 "January 1, 2008"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -590,6 +590,44 @@ where "A0" is year 2000, "B0" is 2010, etc.
\fB\-alter_date_r\fR type timestring iso_rr_path [***]
Like -alter_date but affecting all files below eventual directories.
.TP
\fB\-find\fR iso_rr_path [-name pattern] [-exec action [params]] --
A very restricted substitute for shell command find in the ISO image.
It performs an action on matching file objects at or below iso_rr_path.
.br
Optional -name pattern is not expanded but used for comparison with
the particular file names of the eventual directory tree underneath
iso_rr_path. If no -name pattern is given, then any file name matches.
.br
If a file matches then the action is performed. Default action is "echo",
i.e. to print the address of the found file. Other actions are certain
xorriso commands which get performed on the found files. These commands
may have specific parameters. See also their particular descriptions.
.br
"chown" and "chown_r" change the ownership and get the user id as param.
E.g.: -find -exec chown thomas
.br
"chgrp" and "chgrp_r" change the group attribute and get the group id as param.
E.g.: -find -exec chgrp_r staff
.br
"chmod" and "chmod_r" change access permissions and get a mode string as param.
E.g.: -find -exec chmod a-w,a+r
.br
"alter_date" changes the timestamps.
It gets a type character and a timestring as params.
.br
E.g.: -find -exec alter_date_r "m" "Dec 30 19:34:12 2007"
.br
"lsdl" prints file information like shell command ls -dl. It gets no params.
E.g.: -find -exec lsdl
.br
"find" performs another run of -find on the matching file address. It accepts
the same params as -find, except iso_rr_path.
.br
E.g.: -find -name '???' -exec find -name '[abc]*' -exec chmod a-w,a+r
.br
If not used as last command in the line then the argument list
needs to get terminated by "--".
.TP
\fB\-mkdir\fR iso_rr_path [...]
Create empty directories if they do not exist yet.
Existence as directory generates a WARNING event, existence as
@ -987,35 +1025,6 @@ List size of directories and files in the local filesystem
which match one of the patterns.
Similar to shell command du -sk.
.TP
\fB\-find\fR iso_rr_path [-name pattern] [-exec action [params]] --
A very restricted substitute for shell command find in the ISO image.
It performs an action on matching file objects at or below iso_rr_path.
.br
Optional -name pattern is not expanded but used for comparison with
the particular file names of the eventual directory tree underneath
iso_rr_path. If no -name pattern is given, then any file name matches.
.br
If a file matches then the action is performed. Default action is "echo",
i.e. to print the address of the found file. Other actions are certain
xorriso commands which get performed on the found files. These commands
may have specific parameters. See also their particular descriptions.
.br
"chown" changes the ownership and gets the user id as param.
.br
"chgrp" changes the group attribute and gets the group id as param.
.br
"chmod" changes access permissions and gets a mode string as param.
Like: a-w,a+r
.br
"alter_date" changes the timestamps.
It gets a type character and a timestring as params.
Like: "m" "Dec 30 19:34:12 2007"
.br
"lsdl" prints file information like shell command ls -dl. It gets no params.
.br
If not used as last command in the line then the argument list
needs to get terminated by "--".
.TP
\fB\-findx\fR disk_path [-name pattern] --
Like -find but operating on local filesystem and not on the ISO image.
This action is subject to the settings of -follow.

View File

@ -25,17 +25,50 @@ or
/* Command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Initial code of this program was derived from program src/askme.c out
of scdbackup-0.8.8, Copyright 2007 Thomas Schmitt, BSD-License.
Provided under GPL version 2, with the announcement that this might
get changed in future. I would prefer BSD or a modifyied LGPL with no
get changed in future. I would prefer BSD or a modified LGPL with no
option to choose any kind of future GPL version.
(This announcement affects only future releases of xorriso.
If you obtain a copy licensed as "GPL version 2" then this license is
not revocable for that particular copy, of course.)
Overview of xorriso architecture:
libburn provides the ability to read and write data.
libisofs interprets and manipulates ISO 9660 directory trees. It generates
the output stream which is handed over to libburn.
libisoburn encapsulates the connectivity issues between libburn and
libisofs. It also enables multi-session emulation on overwritable media
and random access file objects.
xorriso is intended as reference application of libisoburn.
xorrisoburn.[ch] encapsulate any usage of the libraries by xorriso.
xorriso.h exposes the public functions of xorriso which are intended
to be used by programs which link with xorriso.o. These functions are
direct equivalents of the xorriso interpreter commands.
There is also the API for handling event messages.
xorriso_private.h is not to be included by other software. It encapsulates
the inner interfaces of xorriso.
xorriso.c provides the command interpreter as described in xorriso.1.
It performs any activity that does not demand a reference to a symbol
of the library APIs. This includes:
- Interpretation of user input from arguments, dialog, and scripting.
- Output of result text and event messages.
- POSIX filesystem operations.
- Public functions which perform the particular xorriso commands.
- The main() function, if enabled by #define Xorriso_with_maiN.
*/
#define PROG_VERSION "0.0.0"
@ -2459,14 +2492,19 @@ struct FindjoB {
#endif
/* 0= echo
1= rm
2= rm_r
3= mv target
>>> 1= rm
>>> 2= rm_r
>>> 3= mv target
4= chown user
5= chgrp group
6= chmod mode
6= chmod mode_and mode_or
7= alter_date type date
8= lsdl
9= chown_r user
10= chgrp_r group
11= chmod_r mode_and mode_or
12= alter_date_r type date
13= find
*/
int action;
char *target;
@ -2475,6 +2513,7 @@ struct FindjoB {
mode_t mode_and, mode_or;
int type; /* see Xorriso_set_time flag */
time_t date;
struct FindjoB *subjob;
};
@ -2496,6 +2535,7 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
m->group= 0;
m->type= 0;
m->date= 0;
m->subjob= NULL;
m->start_path= strdup(start_path);
if(m->start_path==NULL)
goto failed;
@ -2521,12 +2561,27 @@ int Findjob_destroy(struct FindjoB **o, int flag)
#endif
free(m->name_expr);
}
Findjob_destroy(&(m->subjob), 0);
free((char *) m);
*o= NULL;
return(1);
}
int Findjob_set_start_path(struct FindjoB *o, char *start_path, int flag)
{
if(o->start_path!=NULL)
free(o->start_path);
if(start_path!=NULL) {
o->start_path= strdup(start_path);
if(o->start_path==NULL)
return(-1);
} else
o->start_path= NULL;
return(1);
}
int Findjob_set_name_expr(struct FindjoB *o, char *name_expr, int flag)
{
char regexpr[2*SfileadrL+2];
@ -2585,7 +2640,8 @@ int Findjob_get_action(struct FindjoB *o, int flag)
int Findjob_get_action_parms(struct FindjoB *o, char **target,
uid_t *user, gid_t *group,
mode_t *mode_and, mode_t *mode_or,
int *type, time_t *date, int flag)
int *type, time_t *date, struct FindjoB **subjob,
int flag)
{
*target= o->target;
*user= o->user;
@ -2594,6 +2650,7 @@ int Findjob_get_action_parms(struct FindjoB *o, char **target,
*mode_or= o->mode_or;
*type= o->type;
*date= o->date;
*subjob= o->subjob;
return(o->action);
}
@ -2607,37 +2664,103 @@ int Findjob_set_action_target(struct FindjoB *o, int action, char *target,
}
/* @param flag bit0= recursive
*/
int Findjob_set_action_chown(struct FindjoB *o, uid_t user,int flag)
{
int ret;
if(flag&1) {
o->action= 0;
Findjob_destroy(&(o->subjob), 0);
ret= Findjob_new(&(o->subjob), "", 0);
if(ret<=0)
return(-1);
Findjob_set_action_chown(o->subjob, user, 0);
o->action= 9;
} else {
o->action= 4;
o->user= user;
}
return(1);
}
/* @param flag bit0= recursive
*/
int Findjob_set_action_chgrp(struct FindjoB *o, gid_t group, int flag)
{
int ret;
if(flag&1) {
o->action= 0;
Findjob_destroy(&(o->subjob), 0);
ret= Findjob_new(&(o->subjob), "", 0);
if(ret<=0)
return(-1);
Findjob_set_action_chgrp(o->subjob, group, 0);
o->action= 10;
} else {
o->action= 5;
o->group= group;
}
return(1);
}
/* @param flag bit0= recursive
*/
int Findjob_set_action_chmod(struct FindjoB *o,
mode_t mode_and, mode_t mode_or, int flag)
{
int ret;
if(flag&1) {
o->action= 0;
Findjob_destroy(&(o->subjob), 0);
ret= Findjob_new(&(o->subjob), "", 0);
if(ret<=0)
return(-1);
Findjob_set_action_chmod(o->subjob, mode_and, mode_or, 0);
o->action= 11;
} else {
o->action= 6;
o->mode_and= mode_and;
o->mode_or= mode_or;
}
return(1);
}
/* @param flag bit0= recursive
*/
int Findjob_set_action_ad(struct FindjoB *o, int type, time_t date, int flag)
{
int ret;
if(flag&1) {
o->action= 0;
Findjob_destroy(&(o->subjob), 0);
ret= Findjob_new(&(o->subjob), "", 0);
if(ret<=0)
return(-1);
Findjob_set_action_ad(o->subjob, type, date, 0);
o->action= 12;
} else {
o->action= 7;
o->type= type;
o->date= date;
}
return(1);
}
int Findjob_set_action_subjob(struct FindjoB *o, int action,
struct FindjoB *subjob, int flag)
{
o->action= action;
Findjob_destroy(&(o->subjob), 0);
o->subjob= subjob;
return(1);
}
@ -6624,7 +6747,7 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret, i, end_idx, type= 0;
struct FindjoB *job= NULL;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, sfe[5*SfileadrL], *cpt;
struct stat dir_stbuf;
uid_t user= 0;
@ -6636,11 +6759,12 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
start_path= ".";
if(end_idx > *idx && start_path[0]!=0)
start_path= argv[*idx];
ret= Findjob_new(&job, start_path, 0);
ret= Findjob_new(&first_job, start_path, 0);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find[ix]", 0);
{ret= -1; goto ex;}
}
job= first_job;
for(i= *idx+1; i<end_idx; i++) {
if(strcmp(argv[i], "-name")==0) {
@ -6681,23 +6805,31 @@ not_enough_arguments:;
Findjob_set_action_target(job, 3, argv[i], 0);
#endif
} else if(strcmp(cpt, "chown")==0) {
} else if(strcmp(cpt, "chown")==0 || strcmp(cpt, "chown_r")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Xorriso_convert_uidstring(xorriso, argv[i], &user, 0);
if(ret<=0)
goto ex;
Findjob_set_action_chown(job, user, 0);
} else if(strcmp(cpt, "chgrp")==0) {
ret= Findjob_set_action_chown(job, user, strlen(cpt)>5);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find -exec chown_r", 0);
goto ex;
}
} else if(strcmp(cpt, "chgrp")==0 || strcmp(cpt, "chgrp_r")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Xorriso_convert_gidstring(xorriso, argv[i], &group, 0);
if(ret<=0)
goto ex;
Findjob_set_action_chgrp(job, group, 0);
} else if(strcmp(cpt, "chmod")==0) {
ret= Findjob_set_action_chgrp(job, group, strlen(cpt)>5);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find -exec chgrp_r", 0);
goto ex;
}
} else if(strcmp(cpt, "chmod")==0 || strcmp(cpt, "chmod_r")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
@ -6705,8 +6837,12 @@ not_enough_arguments:;
argv[i], &mode_and, &mode_or, 0);
if(ret<=0)
goto ex;
Findjob_set_action_chmod(job, mode_and, mode_or, 0);
} else if(strcmp(cpt, "alter_date")==0) {
ret= Findjob_set_action_chmod(job, mode_and, mode_or, strlen(cpt)>5);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find -exec chmod_r", 0);
goto ex;
}
} else if(strcmp(cpt, "alter_date")==0 || strcmp(cpt, "alter_date_r")==0){
if(i+2>=end_idx)
goto not_enough_arguments;
i+= 2;
@ -6714,9 +6850,22 @@ not_enough_arguments:;
argv[i-1], argv[i], &type, &date, 0);
if(ret<=0)
goto ex;
Findjob_set_action_ad(job, type, date, 0);
ret= Findjob_set_action_ad(job, type, date, strlen(cpt)>10);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find -exec alter_date_r", 0);
goto ex;
}
} else if(strcmp(cpt, "lsdl")==0) {
Findjob_set_action_target(job, 8, NULL, 0);
} else if(strcmp(cpt, "find")==0) {
ret= Findjob_new(&new_job, "", 0);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-find[ix]", 0);
{ret= -1; goto ex;}
}
Findjob_set_action_subjob(job, 13, new_job, 0);
job= new_job;
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
Text_shellsafe(argv[i], sfe, 0));
@ -6731,11 +6880,12 @@ sorry_ex:;
}
}
if(flag&1)
ret= Xorriso_findx(xorriso, job, "", start_path, &dir_stbuf, 0, NULL, 0);
ret= Xorriso_findx(xorriso, first_job, "", start_path, &dir_stbuf, 0, NULL,
0);
else
ret= Xorriso_findi(xorriso, job, NULL, start_path, &dir_stbuf, 0, 0);
ret= Xorriso_findi(xorriso, first_job, NULL, start_path, &dir_stbuf, 0, 0);
ex:;
Findjob_destroy(&job, 0);
Findjob_destroy(&first_job, 0);
(*idx)= end_idx;
return(ret);
}
@ -7973,7 +8123,7 @@ int Xorriso_option_version(struct XorrisO *xorriso, int flag)
sprintf(xorriso->result_line,
"xorriso %s : RockRidge filesystem manipulator\n", PROG_VERSION);
sprintf(xorriso->result_line+strlen(xorriso->result_line),
"Copyright (C) 2007, Thomas Schmitt <scdbackup@gmx.net>, libburnia project\n");
"Copyright (C) 2008, Thomas Schmitt <scdbackup@gmx.net>, libburnia project\n");
sprintf(xorriso->result_line+strlen(xorriso->result_line),
"Version timestamp : %s\n",Xorriso_timestamP);
sprintf(xorriso->result_line+strlen(xorriso->result_line),

View File

@ -2,7 +2,7 @@
/* Command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2.

View File

@ -2,7 +2,7 @@
/* Command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2.
@ -310,8 +310,28 @@ int Findjob_get_action(struct FindjoB *o, int flag);
int Findjob_get_action_parms(struct FindjoB *o, char **target,
uid_t *user, gid_t *group,
mode_t *mode_and, mode_t *mode_or,
int *type, time_t *date, int flag);
int *type, time_t *date, struct FindjoB **subjob,
int flag);
/* @param flag bit0= recursive
*/
int Findjob_set_action_target(struct FindjoB *o, int action, char *target,
int flag);
/* @param flag bit0= recursive
*/
int Findjob_set_action_chgrp(struct FindjoB *o, gid_t group, int flag);
/* @param flag bit0= recursive
*/
int Findjob_set_action_chmod(struct FindjoB *o,
mode_t mode_and, mode_t mode_or, int flag);
/* @param flag bit0= recursive
*/
int Findjob_set_action_ad(struct FindjoB *o, int type, time_t date, int flag);
int Findjob_set_start_path(struct FindjoB *o, char *start_path, int flag);
#endif /* Xorriso_private_includeD */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.12.31.135330"
#define Xorriso_timestamP "2008.01.01.123118"

View File

@ -4,7 +4,7 @@
a command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2.
*/
@ -2820,7 +2820,7 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
char *abs_path, char *show_path,
struct iso_tree_node *node, int flag)
struct iso_tree_node *node, int depth, int flag)
{
int ret, type, action= 0;
uid_t user= 0;
@ -2828,9 +2828,11 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
time_t date= 0;
mode_t mode_or= 0, mode_and= ~1;
char *target, sfe[5*SfileadrL];
struct FindjoB *subjob;
struct stat dir_stbuf;
action= Findjob_get_action_parms(job, &target, &user, &group,
&mode_and, &mode_or, &type, &date, 0);
&mode_and, &mode_or, &type, &date, &subjob, 0);
if(action<0)
action= 0;
@ -2854,6 +2856,9 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_set_time(xorriso, abs_path, date, type&7);
} else if(action==8) { /* lsdl */
ret= Xorriso_ls_filev(xorriso, "", 1, &abs_path, (off_t) 0, 1|2|8);
} else if(action>=9 && action<=13) { /* actions which have own findjobs */
Findjob_set_start_path(subjob, abs_path, 0);
ret= Xorriso_findi(xorriso, subjob, NULL, abs_path, &dir_stbuf, depth, 0);
} else {
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
@ -2924,7 +2929,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
Xorriso_result(xorriso, 0);
#else
ret= Xorriso_findi_action(xorriso, job, path, dir_path,
(struct iso_tree_node *) dir_node, 0);
(struct iso_tree_node *) dir_node, depth, 0);
if(ret<=0)
goto ex;
#endif /* ! NIX */
@ -2964,7 +2969,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, path, abs_path, 1|4);
if(ret<=0)
goto ex;
ret= Xorriso_findi_action(xorriso, job, abs_path, path, node, 0);
ret= Xorriso_findi_action(xorriso, job, abs_path, path, node, depth, 0);
if(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex;

View File

@ -4,7 +4,7 @@
a command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2.