Browse Source

New -find test -disk_path

master
Thomas Schmitt 10 years ago
parent
commit
2edce33c2e
  1. 17
      xorriso/findjob.c
  2. 5
      xorriso/findjob.h
  3. 17
      xorriso/iso_manip.c
  4. 68
      xorriso/iso_tree.c
  5. 23
      xorriso/opts_d_h.c
  6. 10
      xorriso/xorriso.1
  7. 86
      xorriso/xorriso.info
  8. 10
      xorriso/xorriso.texi
  9. 2
      xorriso/xorriso_timestamp.h

17
xorriso/findjob.c

@ -382,6 +382,7 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
m->subjob= NULL;
m->errmsg[0]= 0;
m->errn= 0;
m->match_count= 0;
ret= Exprnode_new(&(m->test_tree), m, NULL, "-find", (m->use_shortcuts)<<1);
if(ret<=0)
@ -758,7 +759,7 @@ improper_range:;
}
/* @param flag bit0-1= 0= -name , 1= -wholename , 2= -disk_name
/* @param flag bit0-1: 0= -name , 1= -wholename , 2= -disk_name , 3= -disk_path
*/
int Findjob_set_name_expr(struct FindjoB *o, char *name_expr, int flag)
{
@ -782,14 +783,18 @@ int Findjob_set_name_expr(struct FindjoB *o, char *name_expr, int flag)
t->test_type= 13;
else if((flag & 3) == 2)
t->test_type= 16;
else if((flag & 3) == 3)
t->test_type= 20;
t->arg1= strdup(name_expr);
if(t->arg1 == NULL)
{ret= -1; goto ex;};
if((flag & 3) == 3)
{ret= 1; goto ex;}
name_re= (regex_t *) calloc(1, sizeof(regex_t));
if(name_re == NULL)
{ret= -1; goto ex;};
t->arg1= strdup(name_expr);
if(t->arg1 == NULL) {
free((char *) name_re);
{ret= -1; goto ex;};
}
Xorriso__bourne_to_reg(name_expr, regexpr, 0);
if(regcomp(name_re, regexpr, 0) != 0) {
free((char *) name_re);

5
xorriso/findjob.h

@ -48,6 +48,7 @@ struct ExprtesT {
17= -hidden int *arg1 (bit0=iso_rr, bit1=joliet)
18= -has_hfs_crtp char *creator char *type
19= -has_hfs_bless int bless_index
20= -disk_path char *arg1
*/
int test_type;
@ -193,6 +194,10 @@ struct FindjoB {
-4 = unsupported command
-5 = -then -elseif -else -endif without -if or at wrong place
*/
/* Counts the test matches */
unsigned long match_count;
};

17
xorriso/iso_manip.c

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2011 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2012 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -2422,6 +2422,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
&mode_and, &mode_or, &type, &date, &subjob, 0);
if(action<0)
action= 0;
job->match_count++;
hflag= 16*!(flag&2);
ret= 1;
@ -2654,6 +2655,8 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
}
/* flag bit0= perform -disk_path rather than -disk_name
*/
int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
IsoNode *node, int flag)
@ -2668,16 +2671,21 @@ int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
ret= Xorriso_retrieve_disk_path(xorriso, node, disk_path, 0);
if(ret <= 0)
{ret= 0; goto ex;}
if(flag & 1) {
if(strcmp(disk_path, ftest->arg1) == 0)
{ret= 1; goto ex;}
{ret= 0; goto ex;}
}
arg2= ftest->arg2;
npt= strrchr(disk_path, '/');
if(npt != NULL)
npt++;
else
npt= disk_path;
ret= regexec(arg2, npt, 1, &name_match, 0);
ret= ! regexec(arg2, npt, 1, &name_match, 0);
ex:;
Xorriso_free_meM(disk_path);
return(!ret);
return(ret);
}
@ -2908,6 +2916,9 @@ return:
value= 1;
}
break; case 20: /* -disk_path */
value= !! Exprtest_match_disk_name(xorriso, ftest, node, 1);
break; default:
/* >>> complain about unknown test type */;

68
xorriso/iso_tree.c

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2011 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2012 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -2069,12 +2069,78 @@ int Xorriso__file_start_lba(IsoNode *node,
}
/* flag bit0= examine sub directories rather than data files
*/
int Xorriso_dir_disk_path(struct XorrisO *xorriso, IsoNode *dir_node,
char disk_path[SfileadrL], int flag)
{
int ret;
char *npt;
IsoNode *node;
IsoDir *dir;
IsoDirIter *iter= NULL;
dir= (IsoDir *) dir_node;
ret= iso_dir_get_children(dir, &iter);
if(ret<0) {
Xorriso_cannot_create_iter(xorriso, ret, 0);
{ret= -1; goto ex;}
}
while(1) {
ret= iso_dir_iter_next(iter, &node);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, "", ret,
"Error when iterating over directory", 0, "FAILURE", 1);
ret= -1; goto ex;
}
if(ret == 0)
break;
if(LIBISO_ISDIR(node) && (flag & 1)) {
ret= Xorriso_dir_disk_path(xorriso, node, disk_path, flag);
if(ret < 0)
goto ex;
if(ret == 0)
continue;
} else if(LIBISO_ISREG(node) && !(flag & 1)) {
ret= Xorriso_retrieve_disk_path(xorriso, node, disk_path, 0);
if(ret < 0)
goto ex;
if(ret == 0)
continue;
} else
continue;
/* Use its parent dir as answer */
npt= strrchr(disk_path, '/');
if(npt == NULL || npt == disk_path)
strcpy(disk_path, "/");
else
*npt= 0;
ret= 1; goto ex;
}
if(!(flag & 1))
ret= Xorriso_dir_disk_path(xorriso, dir_node, disk_path, 1);
else
ret= 0;
ex:
if(iter != NULL)
iso_dir_iter_free(iter);
return(ret);
}
int Xorriso_retrieve_disk_path(struct XorrisO *xorriso, IsoNode *node,
char disk_path[SfileadrL], int flag)
{
IsoFile *file;
IsoStream *stream= NULL, *input_stream;
char type_text[80], *source_path = NULL;
int ret;
if(LIBISO_ISDIR(node)) {
ret= Xorriso_dir_disk_path(xorriso, node, disk_path, 0);
return(ret);
}
if(!LIBISO_ISREG(node))
return(0);

23
xorriso/opts_d_h.c

@ -667,15 +667,17 @@ ex:;
bit2= do not count deleted files with rm and rm_r
bit3= use Xorriso_findi_sorted() rather than Xorriso_findi()
(this can also be ordered by test -sort_lba)
bit4= return number of matches plus 1
*/
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret, i, end_idx, type= 0, action, deleter= 0, start_lba, count;
int list_extattr_head= 0, bsl_mem;
int list_extattr_head= 0, bsl_mem, disk_path;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, *path= NULL, *cpt, *other_path_start= NULL, *cd_pt;
char *access_acl_text= NULL, *default_acl_text= NULL, *list_extattr_mode;
char *arg1_pt;
struct stat dir_stbuf;
uid_t user= 0;
@ -769,14 +771,25 @@ not_enough_arguments:;
Findjob_set_filter_filter(job, -1, 0);
} else if(strcmp(argv[i], "-has_md5")==0) {
Findjob_set_prop_filter(job, 15, 1, 0);
} else if(strcmp(argv[i], "-disk_name")==0) {
} else if(strcmp(argv[i], "-disk_name")==0 ||
strcmp(argv[i], "-disk_path")==0) {
disk_path= (strcmp(argv[i], "-disk_path") == 0);
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Findjob_set_name_expr(job, argv[i], 2);
arg1_pt= argv[i];
if(disk_path) {
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdx, argv[i], path,
1 | 2 | 4 | 8);
if(ret<=0)
goto ex;
arg1_pt= path;
}
ret= Findjob_set_name_expr(job, arg1_pt, 2 + disk_path);
if(ret<=0) {
sprintf(xorriso->info_text,
"-find[ix]: cannot set -disk_name expression ");
"-find[ix]: cannot set %s ",
disk_path ? "-disk_path address" : "-disk_name expression");
Text_shellsafe(argv[i], xorriso->info_text, 1);
goto sorry_ex;
}
@ -1200,6 +1213,8 @@ ex:;
free(access_acl_text);
if(default_acl_text != NULL)
free(default_acl_text);
if(ret > 0 && (flag & 16) && first_job != NULL)
ret= first_job->match_count + 1;
Findjob_destroy(&first_job, 0);
Xorriso_free_meM(path);
Xorriso_free_meM(other_path_start);

10
xorriso/xorriso.1

@ -9,7 +9,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 "Version 1.2.3, Jun 18, 2012"
.TH XORRISO 1 "Version 1.2.3, Jun 21, 2012"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -1641,7 +1641,13 @@ Matches if pattern matches the file path as it would be printed by action
.br
\fB\-disk_name\fR pattern :
Like \-name but testing the leaf name of the file source on disk.
Can be true only for data files which stem not from the loaded image.
Can match only data files which do not stem from the loaded image,
or for directories above such data files. With directories the result can
change between \-find runs if their content stems from multiple sources.
.br
\fB\-disk_path\fR disk_path :
Matches if the given disk_path is equal to the path of the file source
on disk. The same restrictions apply as with \-disk_name.
.br
\fB\-type\fR type_letter :
Matches files of the given type:

86
xorriso/xorriso.info

@ -1488,8 +1488,14 @@ File: xorriso.info, Node: CmdFind, Next: Filter, Prev: Manip, Up: Options
can be matched by wildcards.
-disk_name pattern :
Like -name but testing the leaf name of the file source on
disk. Can be true only for data files which stem not from
the loaded image.
disk. Can match only data files which do not stem from the
loaded image, or for directories above such data files. With
directories the result can change between -find runs if their
content stems from multiple sources.
-disk_path disk_path :
Matches if the given disk_path is equal to the path of the
file source on disk. The same restrictions apply as with
-disk_name.
-type type_letter :
Matches files of the given type: "block", "char", "dir",
"pipe", "file", "link", "socket", "eltorito", and "Xotic"
@ -4997,43 +5003,43 @@ Node: Insert45897
Node: SetInsert55813
Node: Manip64389
Node: CmdFind73212
Node: Filter87568
Node: Writing92123
Node: SetWrite101087
Node: Bootable118920
Node: Jigdo133621
Node: Charset137867
Node: Exception140628
Node: DialogCtl146747
Node: Inquiry149344
Node: Navigate154210
Node: Verify162507
Node: Restore171473
Node: Emulation178382
Node: Scripting188193
Node: Frontend195353
Node: Examples196653
Node: ExDevices197830
Node: ExCreate198489
Node: ExDialog199774
Node: ExGrowing201039
Node: ExModifying201844
Node: ExBootable202348
Node: ExCharset202900
Node: ExPseudo203721
Node: ExCdrecord204619
Node: ExMkisofs204936
Node: ExGrowisofs206276
Node: ExException207411
Node: ExTime207865
Node: ExIncBackup208324
Node: ExRestore212315
Node: ExRecovery213275
Node: Files213845
Node: Seealso215144
Node: Bugreport215867
Node: Legal216448
Node: CommandIdx217459
Node: ConceptIdx233258
Node: Filter87916
Node: Writing92471
Node: SetWrite101435
Node: Bootable119268
Node: Jigdo133969
Node: Charset138215
Node: Exception140976
Node: DialogCtl147095
Node: Inquiry149692
Node: Navigate154558
Node: Verify162855
Node: Restore171821
Node: Emulation178730
Node: Scripting188541
Node: Frontend195701
Node: Examples197001
Node: ExDevices198178
Node: ExCreate198837
Node: ExDialog200122
Node: ExGrowing201387
Node: ExModifying202192
Node: ExBootable202696
Node: ExCharset203248
Node: ExPseudo204069
Node: ExCdrecord204967
Node: ExMkisofs205284
Node: ExGrowisofs206624
Node: ExException207759
Node: ExTime208213
Node: ExIncBackup208672
Node: ExRestore212663
Node: ExRecovery213623
Node: Files214193
Node: Seealso215492
Node: Bugreport216215
Node: Legal216796
Node: CommandIdx217807
Node: ConceptIdx233606

End Tag Table

10
xorriso/xorriso.texi

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO 1 "Version 1.2.3, Jun 18, 2012"
@c man .TH XORRISO 1 "Version 1.2.3, Jun 21, 2012"
@c man .\" Please adjust this date whenever revising the manpage.
@c man .\"
@c man .\" Some roff macros, for reference:
@ -2014,7 +2014,13 @@ Matches if pattern matches the file path as it would be printed by action
@*
@item -disk_name pattern :
Like -name but testing the leaf name of the file source on disk.
Can be true only for data files which stem not from the loaded image.
Can match only data files which do not stem from the loaded image,
or for directories above such data files. With directories the result can
change between -find runs if their content stems from multiple sources.
@*
@item -disk_path disk_path :
Matches if the given disk_path is equal to the path of the file source
on disk. The same restrictions apply as with -disk_name.
@*
@item -type type_letter :
Matches files of the given type:

2
xorriso/xorriso_timestamp.h

@ -1 +1 @@
#define Xorriso_timestamP "2012.06.20.190651"
#define Xorriso_timestamP "2012.06.21.203531"

Loading…
Cancel
Save