Pino Toscano
2014-Mar-20 16:04 UTC
[Libguestfs] [PATCH 1/2] builder: allow the index parser to parse files with no sections
Gracefully handle files with no sections; extend the validate.sh test to try to validate an empty file. --- builder/index-parse.y | 2 ++ builder/website/validate.sh | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/builder/index-parse.y b/builder/index-parse.y index 9355bd4..5133959 100644 --- a/builder/index-parse.y +++ b/builder/index-parse.y @@ -108,6 +108,8 @@ sections: { $$ = $1; } | section EMPTY_LINE emptylines sections { $$ = $1; $$->next = $4; } + | emptylines + { $$ = NULL; } section: SECTION_HEADER fields diff --git a/builder/website/validate.sh b/builder/website/validate.sh index bd9a4ed..f2e24cf 100755 --- a/builder/website/validate.sh +++ b/builder/website/validate.sh @@ -19,6 +19,13 @@ export LANG=C set -e +fn=test-filename-for-index-validate + +rm -f $fn +touch $fn + $VG ../virt-index-validate $srcdir/index $VG ../virt-index-validate $srcdir/index.asc +$VG ../virt-index-validate $fn +rm $fn -- 1.8.3.1
Pino Toscano
2014-Mar-20 16:04 UTC
[Libguestfs] [PATCH 2/2] builder: do not parse the same repository file name twice
When parsing the repository configuration files, track the file names parsed, and in case of same file name in multiple location consider only the one in the directory coming before others in the prioritised list of paths. This way it is possible to "shadow" a configuration file in a system path with one with the same name in a local directory, for example. --- builder/sources.ml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/builder/sources.ml b/builder/sources.ml index 1fee65e..90716bd 100644 --- a/builder/sources.ml +++ b/builder/sources.ml @@ -28,6 +28,8 @@ type source = { gpgkey : string option; } +module StringSet = Set.Make (String) + let parse_conf ~prog ~debug file if debug then ( eprintf (f_"%s: trying to read %s\n") prog file; @@ -96,15 +98,23 @@ let read_sources ~prog ~debug | None -> dirs | Some dir -> dir :: dirs in let dirs = List.map (fun x -> x // "repos.d") dirs in - List.fold_right ( - fun dir acc -> + let fnseen = ref StringSet.empty in + List.fold_left ( + fun acc dir -> let files try List.filter filter_filenames (Array.to_list (Sys.readdir dir)) with Sys_error _ -> [] in - let files = List.map (fun x -> dir // x) files in + let files = List.filter (fun x -> StringSet.mem x !fnseen <> true) files in List.fold_left ( fun acc file -> - try merge_sources acc (parse_conf ~prog ~debug file) with + try ( + let s = merge_sources acc (parse_conf ~prog ~debug (dir // file)) in + (* Add the current file name to the set only if its parsing + * was successful. + *) + fnseen := StringSet.add file !fnseen; + s + ) with | Unix_error (code, fname, _) -> if debug then ( eprintf (f_"%s: file error: %s: %s\n") prog fname (error_message code) @@ -116,4 +126,4 @@ let read_sources ~prog ~debug ); acc ) acc files - ) dirs [] + ) [] dirs -- 1.8.3.1
Richard W.M. Jones
2014-Mar-20 17:23 UTC
Re: [Libguestfs] [PATCH 1/2] builder: allow the index parser to parse files with no sections
On Thu, Mar 20, 2014 at 05:04:24PM +0100, Pino Toscano wrote:> Gracefully handle files with no sections; extend the validate.sh test > to try to validate an empty file. > --- > builder/index-parse.y | 2 ++ > builder/website/validate.sh | 7 +++++++ > 2 files changed, 9 insertions(+) > > diff --git a/builder/index-parse.y b/builder/index-parse.y > index 9355bd4..5133959 100644 > --- a/builder/index-parse.y > +++ b/builder/index-parse.y > @@ -108,6 +108,8 @@ sections: > { $$ = $1; } > | section EMPTY_LINE emptylines sections > { $$ = $1; $$->next = $4; } > + | emptylines > + { $$ = NULL; } > > section: > SECTION_HEADER fields > diff --git a/builder/website/validate.sh b/builder/website/validate.sh > index bd9a4ed..f2e24cf 100755 > --- a/builder/website/validate.sh > +++ b/builder/website/validate.sh > @@ -19,6 +19,13 @@ > export LANG=C > set -e > > +fn=test-filename-for-index-validate > + > +rm -f $fn > +touch $fn > + > $VG ../virt-index-validate $srcdir/index > $VG ../virt-index-validate $srcdir/index.asc > +$VG ../virt-index-validate $fn > > +rm $fn > -- > 1.8.3.1ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2014-Mar-20 17:24 UTC
Re: [Libguestfs] [PATCH 2/2] builder: do not parse the same repository file name twice
On Thu, Mar 20, 2014 at 05:04:25PM +0100, Pino Toscano wrote:> When parsing the repository configuration files, track the file names > parsed, and in case of same file name in multiple location consider only > the one in the directory coming before others in the prioritised list of > paths. > > This way it is possible to "shadow" a configuration file in a system > path with one with the same name in a local directory, for example. > --- > builder/sources.ml | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/builder/sources.ml b/builder/sources.ml > index 1fee65e..90716bd 100644 > --- a/builder/sources.ml > +++ b/builder/sources.ml > @@ -28,6 +28,8 @@ type source = { > gpgkey : string option; > } > > +module StringSet = Set.Make (String) > + > let parse_conf ~prog ~debug file > if debug then ( > eprintf (f_"%s: trying to read %s\n") prog file; > @@ -96,15 +98,23 @@ let read_sources ~prog ~debug > | None -> dirs > | Some dir -> dir :: dirs in > let dirs = List.map (fun x -> x // "repos.d") dirs in > - List.fold_right ( > - fun dir acc -> > + let fnseen = ref StringSet.empty in > + List.fold_left ( > + fun acc dir -> > let files > try List.filter filter_filenames (Array.to_list (Sys.readdir dir)) > with Sys_error _ -> [] in > - let files = List.map (fun x -> dir // x) files in > + let files = List.filter (fun x -> StringSet.mem x !fnseen <> true) files in > List.fold_left ( > fun acc file -> > - try merge_sources acc (parse_conf ~prog ~debug file) with > + try ( > + let s = merge_sources acc (parse_conf ~prog ~debug (dir // file)) in > + (* Add the current file name to the set only if its parsing > + * was successful. > + *) > + fnseen := StringSet.add file !fnseen; > + s > + ) with > | Unix_error (code, fname, _) -> > if debug then ( > eprintf (f_"%s: file error: %s: %s\n") prog fname (error_message code) > @@ -116,4 +126,4 @@ let read_sources ~prog ~debug > ); > acc > ) acc files > - ) dirs [] > + ) [] dirs > -- > 1.8.3.1ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW