Pino Toscano
2018-Dec-03 15:32 UTC
[Libguestfs] [supermin PATCH] build: ignore empty files
Do not error out on empty files, just ignore them. --- src/mode_build.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mode_build.ml b/src/mode_build.ml index b5f5fa6..9cd0a21 100644 --- a/src/mode_build.ml +++ b/src/mode_build.ml @@ -46,6 +46,7 @@ and file_content | Packages | Hostfiles | Excludefiles +| Empty let rec string_of_file_type = function | GZip c -> sprintf "gzip %s" (string_of_file_content c) @@ -56,6 +57,7 @@ and string_of_file_content = function | Packages -> "packages" | Hostfiles -> "hostfiles" | Excludefiles -> "excludefiles" + | Empty -> "(empty)" let rec build debug (copy_kernel, format, host_cpu, @@ -250,6 +252,8 @@ and read_appliance debug basedir appliance = function (* Depending on the file type, read or unpack the file. *) let appliance match file_type with + | Uncompressed Empty | GZip Empty | XZ Empty -> + appliance | Uncompressed ((Packages|Hostfiles|Excludefiles) as t) -> let chan = open_in file in let lines = input_all_lines chan in @@ -294,7 +298,7 @@ and update_appliance appliance lines = function String.sub path 1 (n-1) ) lines in { appliance with excludefiles = appliance.excludefiles @ lines } - | Base_image -> assert false + | Base_image | Empty -> assert false (* Determine the [file_type] of [file], or exit with an error. *) and get_file_type file @@ -331,6 +335,7 @@ and get_file_content file buf len else if len >= 2 && buf.[0] = '/' then Hostfiles else if len >= 2 && buf.[0] = '-' then Excludefiles else if len >= 1 && isalnum buf.[0] then Packages + else if len = 0 then Empty else error "%s: unknown file type in supermin directory" file and get_compressed_file_content zcat file -- 2.17.2
Richard W.M. Jones
2018-Dec-03 15:54 UTC
Re: [Libguestfs] [supermin PATCH] build: ignore empty files
On Mon, Dec 03, 2018 at 04:32:19PM +0100, Pino Toscano wrote:> Do not error out on empty files, just ignore them. > --- > src/mode_build.ml | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/src/mode_build.ml b/src/mode_build.ml > index b5f5fa6..9cd0a21 100644 > --- a/src/mode_build.ml > +++ b/src/mode_build.ml > @@ -46,6 +46,7 @@ and file_content > | Packages > | Hostfiles > | Excludefiles > +| Empty > > let rec string_of_file_type = function > | GZip c -> sprintf "gzip %s" (string_of_file_content c) > @@ -56,6 +57,7 @@ and string_of_file_content = function > | Packages -> "packages" > | Hostfiles -> "hostfiles" > | Excludefiles -> "excludefiles" > + | Empty -> "(empty)" > > let rec build debug > (copy_kernel, format, host_cpu, > @@ -250,6 +252,8 @@ and read_appliance debug basedir appliance = function > (* Depending on the file type, read or unpack the file. *) > let appliance > match file_type with > + | Uncompressed Empty | GZip Empty | XZ Empty -> > + appliance > | Uncompressed ((Packages|Hostfiles|Excludefiles) as t) -> > let chan = open_in file in > let lines = input_all_lines chan in > @@ -294,7 +298,7 @@ and update_appliance appliance lines = function > String.sub path 1 (n-1) > ) lines in > { appliance with excludefiles = appliance.excludefiles @ lines } > - | Base_image -> assert false > + | Base_image | Empty -> assert false > > (* Determine the [file_type] of [file], or exit with an error. *) > and get_file_type file > @@ -331,6 +335,7 @@ and get_file_content file buf len > else if len >= 2 && buf.[0] = '/' then Hostfiles > else if len >= 2 && buf.[0] = '-' then Excludefiles > else if len >= 1 && isalnum buf.[0] then Packages > + else if len = 0 then Empty > else error "%s: unknown file type in supermin directory" file > > and get_compressed_file_content zcat file > --This is fine, ACK. Is there a situation where we have empty files in the supermin directory? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Pino Toscano
2018-Dec-03 16:05 UTC
Re: [Libguestfs] [supermin PATCH] build: ignore empty files
On Monday, 3 December 2018 16:54:14 CET Richard W.M. Jones wrote:> Is there a situation where we have empty files in the supermin > directory?The bigger picture here is when creating an appliance, and none of the packages has config files (it does not happen with libguestfs appliances, while it can if you choose packages carefully). The resulting base.tar.gz is not detected by Mode_build.get_file_type, and I have a couple of patches fixing this. This patch alone fixes the failure at --build time when touching an empty file in the appliance directory. -- Pino Toscano
Martin Kletzander
2018-Dec-03 16:09 UTC
Re: [Libguestfs] [supermin PATCH] build: ignore empty files
On Mon, Dec 03, 2018 at 04:32:19PM +0100, Pino Toscano wrote:>Do not error out on empty files, just ignore them. >--- > src/mode_build.ml | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > >diff --git a/src/mode_build.ml b/src/mode_build.ml >index b5f5fa6..9cd0a21 100644 >--- a/src/mode_build.ml >+++ b/src/mode_build.ml >@@ -46,6 +46,7 @@ and file_content > | Packages > | Hostfiles > | Excludefiles >+| Empty > > let rec string_of_file_type = function > | GZip c -> sprintf "gzip %s" (string_of_file_content c) >@@ -56,6 +57,7 @@ and string_of_file_content = function > | Packages -> "packages" > | Hostfiles -> "hostfiles" > | Excludefiles -> "excludefiles" >+ | Empty -> "(empty)" > > let rec build debug > (copy_kernel, format, host_cpu, >@@ -250,6 +252,8 @@ and read_appliance debug basedir appliance = function > (* Depending on the file type, read or unpack the file. *) > let appliance > match file_type with >+ | Uncompressed Empty | GZip Empty | XZ Empty -> >+ appliance > | Uncompressed ((Packages|Hostfiles|Excludefiles) as t) -> > let chan = open_in file in > let lines = input_all_lines chan in >@@ -294,7 +298,7 @@ and update_appliance appliance lines = function > String.sub path 1 (n-1) > ) lines in > { appliance with excludefiles = appliance.excludefiles @ lines } >- | Base_image -> assert false >+ | Base_image | Empty -> assert false > > (* Determine the [file_type] of [file], or exit with an error. *) > and get_file_type file >@@ -331,6 +335,7 @@ and get_file_content file buf len > else if len >= 2 && buf.[0] = '/' then Hostfiles > else if len >= 2 && buf.[0] = '-' then Excludefiles > else if len >= 1 && isalnum buf.[0] then Packages >+ else if len = 0 then EmptyFor me `zcat` outputs 10 KB of zeroes when ran with the empty base.tar.gz so this is not enough. The following works for me, but is probably not the right way to approach it: diff --git i/src/mode_build.ml w/src/mode_build.ml index 9cd0a21d4c44..9fdfe7fb3729 100644 --- i/src/mode_build.ml +++ w/src/mode_build.ml @@ -336,6 +336,7 @@ and get_file_content file buf len else if len >= 2 && buf.[0] = '-' then Excludefiles else if len >= 1 && isalnum buf.[0] then Packages else if len = 0 then Empty + else if buf = String.make len '\000' then Empty else error "%s: unknown file type in supermin directory" file and get_compressed_file_content zcat file --> else error "%s: unknown file type in supermin directory" file > > and get_compressed_file_content zcat file >-- >2.17.2 > >_______________________________________________ >Libguestfs mailing list >Libguestfs@redhat.com >https://www.redhat.com/mailman/listinfo/libguestfs
Possibly Parallel Threads
- [supermin PATCH v2 0/3] Better handle no config files
- Re: [supermin PATCH] build: ignore empty files
- [supermin PATCH v2 0/4] Check for output results for --if-newer (RHBZ#1813809)
- [supermin PATCH 0/4] Check for output results for --if-newer (RHBZ#1813809)
- [PATCH 0/3] supermin: miscellaneous cleanups