search for: last_part_of

Displaying 20 results from an estimated 69 matches for "last_part_of".

2015 Jul 01
0
[PATCH 2/3] mllib: add and use last_part_of
...estfs.guestfs) root password let users = Array.to_list (g#aug_ls "/files/etc/shadow") in List.iter ( fun userpath -> - let user = - let i = String.rindex userpath '/' in - String.sub userpath (i+1) (String.length userpath -i-1) in + let user = last_part_of userpath '/' in try (* Each line is: "user:[!!]password:..." * !! at the front of the password field means the account is locked. diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 3737b4c..8601009 100644 --- a/mllib/common_utils.ml +++ b/ml...
2015 Jul 01
4
[PATCH 1/2] mllib: add and use last_part_of
...rd.ml @@ -98,8 +98,9 @@ let rec set_linux_passwords ?password_crypto (g : Guestfs.guestfs) root password List.iter ( fun userpath -> let user = - let i = String.rindex userpath '/' in - String.sub userpath (i+1) (String.length userpath -i-1) in + match last_part_of userpath '/' with + | Some x -> x + | None -> error "password: missing '/' in %s" userpath in try (* Each line is: "user:[!!]password:..." * !! at the front of the password field means the account is locked. diff --gi...
2015 Jul 01
0
Re: [PATCH 1/2] mllib: add and use last_part_of
...c set_linux_passwords ?password_crypto (g : Guestfs.guestfs) root password > List.iter ( > fun userpath -> > let user = > - let i = String.rindex userpath '/' in > - String.sub userpath (i+1) (String.length userpath -i-1) in > + match last_part_of userpath '/' with > + | Some x -> x > + | None -> error "password: missing '/' in %s" userpath in Best to translate these strings: | None -> error (f_"password: missing '/' in %s") userpath in > try >...
2015 Jul 01
1
Re: [PATCH 1/2] mllib: add and use last_part_of
...d_crypto (g : Guestfs.guestfs) root password > > List.iter ( > > fun userpath -> > > let user = > > - let i = String.rindex userpath '/' in > > - String.sub userpath (i+1) (String.length userpath -i-1) in > > + match last_part_of userpath '/' with > > + | Some x -> x > > + | None -> error "password: missing '/' in %s" userpath in > > Best to translate these strings: > > | None -> error (f_"password: missing '/' in %s") userpath in...
2015 Jul 01
5
[PATCH 1/3] mllib: add an optional filter for rm_rf_only_files
This way it is possible to use rm_rf_only_files, but not removing specific files. --- mllib/common_utils.ml | 8 +++++++- mllib/common_utils.mli | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 516cff3..3737b4c 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -640,13 +640,19 @@ let rmdir_on_exit = *
2016 Jun 03
2
[PATCH] v2v: copy all driver files into guest
...00644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -291,17 +291,6 @@ and virtio_iso_path_matches_guest_os path inspect = * elements. *) let lc_path = String.lowercase_ascii path in - let lc_basename = Filename.basename lc_path in - - let extension = - match last_part_of lc_basename '.' with - | Some x -> x - | None -> raise Not_found - in - - (* Skip files without specific extensions. *) - let extensions = ["cat"; "inf"; "pdb"; "sys"] in - if not (List.mem extension extensions) then raise...
2016 Nov 01
3
[PATCH v3] v2v: bootloaders: search grub config for all distributions
From: Pavel Butsykin <pbutsykin@virtuozzo.com> This patch improves the search of grub config on EFI partition. This means that the config will be found not only for rhel but also for many other distributions. Tests were performed on the following distributions: centos, fedora, ubuntu, suse. In all cases, the config path was /boot/efi/EFI/*distname*/grub.cfg The main purpose of the patch
2015 Jul 17
0
[PATCH 1/2] mllib: add and use read_first_line_from_file
...* Permissible characters in a salt. *) let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./" diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 083c5d5..f9e8996 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -745,3 +745,9 @@ let last_part_of str sep = let i = String.rindex str sep in Some (String.sub str (i+1) (String.length str - (i+1))) with Not_found -> None + +let read_first_line_from_file filename = + let chan = open_in filename in + let line = input_line chan in + close_in chan; + line diff --git a/mllib/commo...
2016 Aug 08
1
[PATCH] v2v: disk: strip only common extension (RHBZ#1365005)
...* the filename passed in. Users can override this using the * `-on name' option. *) - let name = Filename.basename disk in let name = - try Filename.chop_extension name with Invalid_argument _ -> name in + let name = Filename.basename disk in + let ext = last_part_of name '.' in + (* Remove the extension, only if it's one usually used for disk images. *) + match ext with + | Some ("img"|"qcow2"|"raw"|"vmdk") -> Filename.chop_extension name + | None | Some _ -> name in if name = &...
2015 Aug 10
0
[PATCH 3/4] v2v: copy virtio drivers without guestfs handle leak
...= g#find "/" in - let paths = Array.to_list paths in - let paths = List.map ((^) "/") paths in - let paths = List.filter (g#is_file ~followsymlinks:false) paths in - List.map ( - fun path -> - let basename = - match last_part_of path '/' with - | Some x -> x - | None -> - error "v2v/find_virtio_win_drivers: missing '/' in %s" path in - (path, sprintf "%s:%s" virtio_win path, - basename, - fun () -> g#rea...
2016 Nov 01
0
Re: [PATCH v3] v2v: bootloaders: search grub config for all distributions
...ome Grub2 > + else if String.is_suffix path "/grub.conf" || > + String.is_suffix path "/menu.lst" then > + Some Grub1 > + else > + None Our String.is_suffix is a does String.sub every time, so this is a bit inefficient -- I'd use Common_utils.last_part_of: let bootloader_type_of_filename path = match last_part_of path '/' with | Some "grub.cfg" -> Some Grub2 | Some ("grub.conf"|"menu.lst") -> Some Grub1 | Some _ | None -> None > +(* Where to start searching for bootloaders. *) &gt...
2015 Oct 13
2
[PATCH v2 2/4] v2v: copy virtio drivers without guestfs handle leak
...= g#find "/" in - let paths = Array.to_list paths in - let paths = List.map ((^) "/") paths in - let paths = List.filter (g#is_file ~followsymlinks:false) paths in - List.map ( - fun path -> - let basename = - match last_part_of path '/' with - | Some x -> x - | None -> - error "v2v/find_virtio_win_drivers: missing '/' in %s" path in - (path, sprintf "%s:%s" virtio_win path, - basename, - fun () -> g#rea...
2015 Aug 10
15
[PATCH 0/4] v2v: simplify driver copying from virtio-win iso
Libguestfs supports passing an ISO image as a source of virtio windows drivers to v2v. That support, however, looks too heavy-weight: in order to access those drivers, a separate guestfs handle is created (and thus a new emulator process is started), which runs until v2v completes. This series attempts to make it simpler and lighter-weight, by making the relevant code more local, and by
2015 Oct 14
5
[PATCH v3 0/3] v2v: simplify driver copying from virtio-win iso
Libguestfs supports passing an ISO image as a source of virtio windows drivers to v2v. This series attempts to make it simpler and better scoped. Roman Kagan (3): v2v: consolidate virtio-win file copying v2v: copy virtio drivers without guestfs handle leak v2v: drop useless forced gc --- changes since v2: - drop patch 4 (reuse of the master guestfs handle for hot-adding the ISO image)
2015 Jul 01
0
[PATCH 3/3] sysprep: rework and fix cron-spool operation (RHBZ#1229305)
...8,19 +18,32 @@ open Sysprep_operation open Common_gettext.Gettext +open Common_utils module G = Guestfs let cron_spool_perform (g : Guestfs.guestfs) root side_effects = - Array.iter g#rm_rf (g#glob_expand "/var/spool/cron/*"); + let is_seq path = + let basename = + try last_part_of path '/' + with Not_found -> path in + basename = ".SEQ" in + let reset f = + if g#is_file f then + (* This should overwrite the file in-place, as it's a very + * small buffer which will be handled using internal_write. + * This way, existing at...
2015 Jul 01
0
[PATCH 2/2] sysprep: rework and fix cron-spool operation (RHBZ#1229305)
...19 +18,33 @@ open Sysprep_operation open Common_gettext.Gettext +open Common_utils module G = Guestfs let cron_spool_perform (g : Guestfs.guestfs) root side_effects = - Array.iter g#rm_rf (g#glob_expand "/var/spool/cron/*"); + let is_seq path = + let basename = + match last_part_of path '/' with + | Some x -> x + | None -> path in + basename = ".SEQ" in + let reset f = + if g#is_file f then + (* This should overwrite the file in-place, as it's a very + * small buffer which will be handled using internal_write. + *...
2015 Oct 05
0
[PATCH 5/6] v2v:utils: ignore files w/o extension
...m> --- v2v/utils.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/v2v/utils.ml b/v2v/utils.ml index e07f7a9..23d9e51 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -238,9 +238,8 @@ let find_virtio_win_drivers virtio_win = let extension = match last_part_of lc_basename '.' with | Some x -> x - | None -> - error "v2v/find_virtio_win_drivers: missing '.' in %s" - lc_basename in + | None -> raise Not_found + in (* Skip files without spe...
2016 Jun 03
0
Re: [PATCH] v2v: copy all driver files into guest
...v2v/windows_virtio.ml > @@ -291,17 +291,6 @@ and virtio_iso_path_matches_guest_os path inspect = > * elements. > *) > let lc_path = String.lowercase_ascii path in > - let lc_basename = Filename.basename lc_path in > - > - let extension = > - match last_part_of lc_basename '.' with > - | Some x -> x > - | None -> raise Not_found > - in > - > - (* Skip files without specific extensions. *) > - let extensions = ["cat"; "inf"; "pdb"; "sys"] in > - if not (List.me...
2015 Oct 06
0
[PATCH 3/5] mllib: Add (Char|String).(lower|upper)case_ascii functions.
...lements. *) - let lc_path = String.lowercase path in - let lc_basename = String.lowercase basename in + let lc_path = String.lowercase_ascii path in + let lc_basename = String.lowercase_ascii basename in let extension = match last_part_of lc_basename '.' with -- 2.5.0
2016 Oct 31
0
Re: [PATCH] v2v: bootloaders: search grub config for all distributions
...> + match res with > + | None -> find_grub dirs configs > + | Some (cfg_path, typ) -> cfg_path, typ > + in > + > + find_grub (Array.to_list (g#ls boot_location)) grub_configs in It sounds like this could be simplified by using g#find + Common_utils.last_part_of (to extract the basename of each path, never use Filename.basename for paths in the appliance!) + comparison with the elements in the grub_configs array of this patch. > match typ with > | Grub1 -> > - if config_file = "/boot/efi/EFI/redhat/grub.conf" then > -...