[PATCH] common/mlstdutils: Add chomp function to remove \n from end of strings.
by Richard W.M. Jones
This is like the Perl chomp function, it removes a single \n from the
end of a string if present, else leaves the string alone.
I believe I found the only (two) places where such a function is used,
but there may be a few more lurking.
---
common/mlstdutils/std_utils.ml | 7 +++++++
common/mlstdutils/std_utils.mli | 2 ++
common/mlstdutils/std_utils_tests.ml | 10 ++++++++++
mllib/common_utils.ml | 10 ++--------
v2v/linux_bootloaders.ml | 8 ++------
5 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/common/mlstdutils/std_utils.ml b/common/mlstdutils/std_utils.ml
index 374507662..b731b8fd5 100644
--- a/common/mlstdutils/std_utils.ml
+++ b/common/mlstdutils/std_utils.ml
@@ -229,6 +229,13 @@ module String = struct
let trim ?(test = Char.isspace) str =
trimr ~test (triml ~test str)
+ let chomp str =
+ let n = String.length str in
+ if n > 0 && str.[n-1] = '\n' then
+ String.sub str 0 (n-1)
+ else
+ str
+
let count_chars c str =
let count = ref 0 in
for i = 0 to String.length str - 1 do
diff --git a/common/mlstdutils/std_utils.mli b/common/mlstdutils/std_utils.mli
index 0b7d90736..d217e48d4 100644
--- a/common/mlstdutils/std_utils.mli
+++ b/common/mlstdutils/std_utils.mli
@@ -107,6 +107,8 @@ module String : sig
(** Trim right. *)
val trim : ?test:(char -> bool) -> string -> string
(** Trim left and right. *)
+ val chomp : string -> string
+ (** If the string ends with [\n], remove it. *)
val count_chars : char -> string -> int
(** Count number of times the character occurs in string. *)
val explode : string -> char list
diff --git a/common/mlstdutils/std_utils_tests.ml b/common/mlstdutils/std_utils_tests.ml
index 2789766c6..ce49c7606 100644
--- a/common/mlstdutils/std_utils_tests.ml
+++ b/common/mlstdutils/std_utils_tests.ml
@@ -110,6 +110,15 @@ let test_string_span ctx =
assert_equal_int 3 (String.cspan "def" "ab");
assert_equal_int 0 (String.cspan "" "ab")
+(* Test Std_utils.String.chomp. *)
+let test_string_chomp ctx =
+ assert_equal_string "a" (String.chomp "a");
+ assert_equal_string "a" (String.chomp "a\n");
+ assert_equal_string "a\nb" (String.chomp "a\nb");
+ assert_equal_string "" (String.chomp "");
+ assert_equal_string "" (String.chomp "\n");
+ assert_equal_string "\n" (String.chomp "\n\n") (* only removes one *)
+
(* Suites declaration. *)
let suite =
"mllib Std_utils" >:::
@@ -122,6 +131,7 @@ let suite =
"strings.find" >:: test_string_find;
"strings.lines_split" >:: test_string_lines_split;
"strings.span" >:: test_string_span;
+ "strings.chomp" >:: test_string_chomp;
]
let () =
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 73c6e2473..597128967 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -376,14 +376,8 @@ let shell_command ?(echo_cmd = true) cmd =
let uuidgen () =
let lines = external_command "uuidgen -r" in
assert (List.length lines >= 1);
- let uuid = List.hd lines in
- let len = String.length uuid in
- let uuid, len =
- if len > 0 && uuid.[len-1] = '\n' then
- String.sub uuid 0 (len-1), len-1
- else
- uuid, len in
- if len < 10 then assert false; (* sanity check on uuidgen *)
+ let uuid = String.chomp (List.hd lines) in
+ if String.length uuid < 10 then assert false; (* sanity check on uuidgen *)
uuid
(* Remove a temporary directory on exit. *)
diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index d76407670..210cce762 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -307,12 +307,8 @@ object (self)
match res with
| None -> None
| Some k ->
- let len = String.length k in
- let k =
- if len > 0 && k.[len-1] = '\n' then
- String.sub k 0 (len-1)
- else k in
- Some (remove_hd_prefix k)
+ let k = String.chomp k in
+ Some (remove_hd_prefix k)
in
let vmlinuzes =
--
2.13.2
7 years, 4 months
[PATCH] appliance: read ID_LIKE from os-release as a fallback
by Cédric Bosdonnat
In the appliance used to build the packages for openSUSE, os-release
is super minimal and only had ID_LIKE=suse. The code setting the
DISTRO variable only searches for ID variable so far, resulting in
invalid packagelist on openSUSE.
This fix reads ID_LIKE as a fallback if ID contains nothing.
---
m4/guestfs_appliance.m4 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4
index fbba3373f..ce45256bc 100644
--- a/m4/guestfs_appliance.m4
+++ b/m4/guestfs_appliance.m4
@@ -97,9 +97,15 @@ AC_MSG_CHECKING([which Linux distro for package names])
if test -f /etc/os-release; then
( . /etc/os-release && echo $ID | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@' ) >&AS_MESSAGE_LOG_FD
DISTRO="`. /etc/os-release && echo $ID | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'`"
+ dnl when building SUSE-family packages, the OBS appliance has no ID in os-release,
+ dnl only ID_LIKE set to suse. Read ID_LIKE as a fallback if no ID is found.
+ if test -z "$DISTRO"; then
+ ( . /etc/os-release && echo $ID_LIKE | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@' ) >&AS_MESSAGE_LOG_FD
+ DISTRO="`. /etc/os-release && echo $ID_LIKE | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'`"
+ fi
AS_CASE([$DISTRO],
[FEDORA | RHEL | CENTOS],[DISTRO=REDHAT],
- [OPENSUSE | SLED | SLES],[DISTRO=SUSE],
+ [OPENSUSE | SLED | SLES | SUSE],[DISTRO=SUSE],
[ARCH],[DISTRO=ARCHLINUX])
elif test -f /etc/debian_version; then
DISTRO=DEBIAN
--
2.13.2
7 years, 4 months
[PATCH v7 0/9] Introducing virt-builder-repository
by Cédric Bosdonnat
Hi all,
Here is an update of the series fixing Pino's latest comment.
It just doesn't implement the change based on never-accepted
run commands patch.
Cédric Bosdonnat (9):
lib/osinfo.c: Extract xml processing into a callback
lib: extract osinfo DB traversing API
mllib: ocaml wrapper for lib/osinfo
builder: rename docs test script
builder: add a template parameter to get_index
builder: add Index.write_entry function
mllib: add do_mv helper function to Common_utils
mllib: add XPath helper xpath_get_nodes()
Add a virt-builder-repository tool
.gitignore | 4 +
builder/Makefile.am | 124 ++++-
builder/builder.ml | 2 +-
builder/index.mli | 3 +
builder/index_parser.ml | 80 ++-
builder/index_parser.mli | 8 +-
builder/index_parser_tests.ml | 129 +++++
builder/repository_main.ml | 584 +++++++++++++++++++++
.../{test-virt-builder-docs.sh => test-docs.sh} | 2 +
builder/virt-builder-repository.pod | 213 ++++++++
lib/Makefile.am | 2 +
lib/osinfo-iso.c | 462 ++++++++++++++++
lib/osinfo.c | 489 ++---------------
lib/osinfo.h | 27 +
mllib/Makefile.am | 11 +-
mllib/common_utils.ml | 6 +
mllib/common_utils.mli | 3 +
mllib/osinfo-c.c | 103 ++++
mllib/osinfo.ml | 26 +
mllib/osinfo.mli | 31 ++
mllib/xpath_helpers.ml | 9 +
mllib/xpath_helpers.mli | 4 +
22 files changed, 1869 insertions(+), 453 deletions(-)
create mode 100644 builder/index_parser_tests.ml
create mode 100644 builder/repository_main.ml
rename builder/{test-virt-builder-docs.sh => test-docs.sh} (93%)
create mode 100644 builder/virt-builder-repository.pod
create mode 100644 lib/osinfo-iso.c
create mode 100644 lib/osinfo.h
create mode 100644 mllib/osinfo-c.c
create mode 100644 mllib/osinfo.ml
create mode 100644 mllib/osinfo.mli
--
2.12.2
7 years, 4 months
Is thread-safe for pread_device in python?
by 陳培泓
I want to test performance on reading one 1GB qcow2 file in python
I create multiple threads and read the qcow2 file by pread_device function
in python. And these threads share the same guest handler and device
Is pread_device thread-safe?
My result always shows pread_device can't get reply and corrupted
7 years, 4 months
[PATCH] v2v: bootloaders: Handle no Bootloader::Tools default section (RHBZ#1472208).
by Richard W.M. Jones
In SUSE guests, handle the case where
Bootloader::Tools::GetDefaultSection () returns undef.
Previously this would return an empty string and cause a bogus error
in subsequent code:
virt-v2v: error: libguestfs error: statns: statns_stub: path must start
with a / character
---
v2v/linux_bootloaders.ml | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index b5ad25508..d76407670 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -287,10 +287,21 @@ object (self)
let cmd =
[| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; "
InitLibrary();
- my $default = Bootloader::Tools::GetDefaultSection();
- print $default->{image};
+ my $default = Bootloader::Tools::GetDefaultSection ();
+ if (!defined $default) {
+ print 'NODEFAULTSECTION'
+ }
+ elsif (exists $default->{image}) {
+ print $default->{image}
+ }
+ else {
+ die 'no $default->{image}' # should never happen
+ }
" |] in
- Some (g#command cmd)
+ let res = g#command cmd in
+ (match res with
+ | "NODEFAULTSECTION" -> None
+ | _ -> Some res)
| MethodNone ->
None in
match res with
--
2.13.2
7 years, 4 months
[hivex PATCH 1/2] hivexregedit: fix POD markup
by Pino Toscano
Put the "=back" to close the list only after the last element.
---
regedit/hivexregedit | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/regedit/hivexregedit b/regedit/hivexregedit
index 02c382b..cd49063 100755
--- a/regedit/hivexregedit
+++ b/regedit/hivexregedit
@@ -248,8 +248,6 @@ You should only use this option for quick hacking and debugging of the
hive contents, and I<never> use it if the output is going to be passed
into another program or stored in another hive.
-=back
-
=cut
my $unsafe;
@@ -261,6 +259,8 @@ Use heuristics to tolerate certain levels of corruption within hives.
This is unsafe but may allow to export/merge valid keys/values in an
othewise corrupted hive.
+=back
+
=cut
GetOptions ("help|?" => \$help,
--
2.9.4
7 years, 4 months