[PATCH] sysprep: allow to specify globbing for --delete
Adapt the globbing part from the old --remote-path work previously proposed for sysprep [1], allowing --delete to perform globbing when deleting paths. [1] https://www.redhat.com/archives/libguestfs/2013-October/msg00045.html --- sysprep/sysprep_operation_delete.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index de78a87..59d5485 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -27,7 +27,9 @@ let add_paths path = paths := path :: !paths let path_perform g root = let paths = List.rev !paths in - List.iter g#rm_rf paths; + if paths <> [] then ( + List.iter (fun glob -> Array.iter g#rm_rf (g#glob_expand glob)) paths + ); [] let op = { -- 1.8.3.1
On Mon, Dec 09, 2013 at 04:19:12PM +0100, Pino Toscano wrote:
Adapt the globbing part from the old --remote-path work previously proposed for sysprep [1], allowing --delete to perform globbing when deleting paths.
[1] https://www.redhat.com/archives/libguestfs/2013-October/msg00045.html --- sysprep/sysprep_operation_delete.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index de78a87..59d5485 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -27,7 +27,9 @@ let add_paths path = paths := path :: !paths
let path_perform g root = let paths = List.rev !paths in - List.iter g#rm_rf paths; + if paths <> [] then ( + List.iter (fun glob -> Array.iter g#rm_rf (g#glob_expand glob)) paths + ); []
let op = { -- 1.8.3.1
ACK, but should we update the documentation too? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Followup of ed4bcb119cb908e98ecc1107dcd8b740ee2f484f. --- sysprep/sysprep_operation_delete.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index 59d5485..a08d4d0 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -40,7 +40,10 @@ let op = { pod_description = Some (s_"\ Delete specified files or directories. -Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path, i.e. +C</some/dir/prefix*>."); extra_args = [ { extra_argspec = ("--delete", Arg.String add_paths, s_"path" ^ " " ^ s_"File or directory to be removed on guest"); extra_pod_argval = Some "PATHNAME"; -- 1.8.3.1
On Mon, Dec 09, 2013 at 06:17:00PM +0100, Pino Toscano wrote:
Followup of ed4bcb119cb908e98ecc1107dcd8b740ee2f484f. --- sysprep/sysprep_operation_delete.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index 59d5485..a08d4d0 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -40,7 +40,10 @@ let op = { pod_description = Some (s_"\ Delete specified files or directories.
-Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path, i.e. +C</some/dir/prefix*>.");
How about /var/log/*.log as the example? Also I think we should tell people to quote the arg to defend it from the shell. So it could look like this: -Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path, +for example: + + virt-sysprep --delete '/var/log/*.log'"); (Putting a space in front makes verbatim text in POD) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
On Monday 09 December 2013 17:58:37 Richard W.M. Jones wrote:
On Mon, Dec 09, 2013 at 06:17:00PM +0100, Pino Toscano wrote:
Followup of ed4bcb119cb908e98ecc1107dcd8b740ee2f484f. ---
sysprep/sysprep_operation_delete.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index 59d5485..a08d4d0 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -40,7 +40,10 @@ let op = {
pod_description = Some (s_"\
Delete specified files or directories.
-Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path, i.e. +C</some/dir/prefix*>.");
How about /var/log/*.log as the example? Also I think we should tell people to quote the arg to defend it from the shell. So it could look like this:
-Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path, +for example: + + virt-sysprep --delete '/var/log/*.log'");
(Putting a space in front makes verbatim text in POD)
Good starting point, I've spelt the escaping need explicitly; updated patch coming. -- Pino Toscano
Followup of ed4bcb119cb908e98ecc1107dcd8b740ee2f484f. --- sysprep/sysprep_operation_delete.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index 59d5485..3db3f57 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -40,7 +40,12 @@ let op = { pod_description = Some (s_"\ Delete specified files or directories. -Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path; note that such +metacharacters might require proper escape. For example: + + virt-sysprep --delete '/var/log/*.log'."); extra_args = [ { extra_argspec = ("--delete", Arg.String add_paths, s_"path" ^ " " ^ s_"File or directory to be removed on guest"); extra_pod_argval = Some "PATHNAME"; -- 1.8.3.1
On Mon, Dec 09, 2013 at 07:40:44PM +0100, Pino Toscano wrote:
Followup of ed4bcb119cb908e98ecc1107dcd8b740ee2f484f. --- sysprep/sysprep_operation_delete.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml index 59d5485..3db3f57 100644 --- a/sysprep/sysprep_operation_delete.ml +++ b/sysprep/sysprep_operation_delete.ml @@ -40,7 +40,12 @@ let op = { pod_description = Some (s_"\ Delete specified files or directories.
-Use the I<--delete> option to specify a path to remove."); +Use the I<--delete> option to specify a path to remove. + +You can use shell glob characters in the specified path; note that such +metacharacters might require proper escape. For example: + + virt-sysprep --delete '/var/log/*.log'."); extra_args = [ { extra_argspec = ("--delete", Arg.String add_paths, s_"path" ^ " " ^ s_"File or directory to be removed on guest"); extra_pod_argval = Some "PATHNAME"; -- 1.8.3.1
ACK. 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
participants (2)
-
Pino Toscano -
Richard W.M. Jones