[virt-tools-list] [PATCH virt-viewer] file: add delete-this-file option

Hans de Goede hdegoede at redhat.com
Wed May 1 07:00:16 UTC 2013


Hi,

Looks good, ACK.

Regards,

Hans


On 04/30/2013 02:33 AM, Marc-André Lureau wrote:
> In case the virt-viewer setting file is meant to temporary, you may use
> the delete-this-file=1 option to ask the client to remove it, once it
> has been read. This is useful for example in ovirt context, where
> connection settings file are generated and can't be reused.
> ---
>   src/virt-viewer-file.c | 32 ++++++++++++++++++++++++++++++++
>   src/virt-viewer-file.h |  2 ++
>   2 files changed, 34 insertions(+)
>
> diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
> index 12b8c31..3636c2e 100644
> --- a/src/virt-viewer-file.c
> +++ b/src/virt-viewer-file.c
> @@ -22,6 +22,7 @@
>   #include <config.h>
>
>   #include <glib/gi18n.h>
> +#include <glib/gstdio.h>
>
>   #include "virt-viewer-util.h"
>   #include "virt-viewer-file.h"
> @@ -61,6 +62,7 @@
>    * - enable-usb-autoshare: int
>    * - usb-filter: string
>    * - secure-channels: string list
> + * - delete-this-file: int (0 or 1 atm)
>    *
>    * (the file can be extended with extra groups or keys, which should
>    * be prefixed with x- to avoid later conflicts)
> @@ -101,6 +103,7 @@ enum  {
>       PROP_PROXY,
>       PROP_VERSION,
>       PROP_SECURE_CHANNELS,
> +    PROP_DELETE_THIS_FILE,
>   };
>
>   VirtViewerFile*
> @@ -131,6 +134,12 @@ virt_viewer_file_new(const gchar* location, GError** error)
>           return NULL;
>       }
>
> +    if (virt_viewer_file_get_delete_this_file(self) &&
> +        !g_getenv("VIRT_VIEWER_KEEP_FILE")) {
> +        if (g_unlink(location) != 0)
> +            g_warning("failed to remove %s", location);
> +    }
> +
>       return self;
>   }
>
> @@ -479,6 +488,19 @@ virt_viewer_file_set_enable_usbredir(VirtViewerFile* self, gint value)
>   }
>
>   gint
> +virt_viewer_file_get_delete_this_file(VirtViewerFile* self)
> +{
> +    return virt_viewer_file_get_int(self, "delete-this-file");
> +}
> +
> +void
> +virt_viewer_file_set_delete_this_file(VirtViewerFile* self, gint value)
> +{
> +    virt_viewer_file_set_int(self, "delete-this-file", !!value);
> +    g_object_notify(G_OBJECT(self), "delete-this-file");
> +}
> +
> +gint
>   virt_viewer_file_get_color_depth(VirtViewerFile* self)
>   {
>       return virt_viewer_file_get_int(self, "color-depth");
> @@ -709,6 +731,9 @@ virt_viewer_file_set_property(GObject* object, guint property_id,
>           strv = g_value_get_boxed(value);
>           virt_viewer_file_set_secure_channels(self, (const gchar* const*)strv, g_strv_length(strv));
>           break;
> +    case PROP_DELETE_THIS_FILE:
> +        virt_viewer_file_set_delete_this_file(self, g_value_get_int(value));
> +        break;
>       default:
>           G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
>           break;
> @@ -791,6 +816,9 @@ virt_viewer_file_get_property(GObject* object, guint property_id,
>       case PROP_SECURE_CHANNELS:
>           g_value_take_boxed(value, virt_viewer_file_get_secure_channels(self, NULL));
>           break;
> +    case PROP_DELETE_THIS_FILE:
> +        g_value_set_int(value, virt_viewer_file_get_delete_this_file(self));
> +        break;
>       default:
>           G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
>           break;
> @@ -917,4 +945,8 @@ virt_viewer_file_class_init(VirtViewerFileClass* klass)
>       g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SECURE_CHANNELS,
>           g_param_spec_boxed("secure-channels", "secure-channels", "secure-channels", G_TYPE_STRV,
>                              G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
> +
> +    g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_DELETE_THIS_FILE,
> +        g_param_spec_int("delete-this-file", "delete-this-file", "delete-this-file", 0, 1, 0,
> +                         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
>   }
> diff --git a/src/virt-viewer-file.h b/src/virt-viewer-file.h
> index 7c48856..8665070 100644
> --- a/src/virt-viewer-file.h
> +++ b/src/virt-viewer-file.h
> @@ -104,6 +104,8 @@ gchar* virt_viewer_file_get_version(VirtViewerFile* self);
>   void virt_viewer_file_set_version(VirtViewerFile* self, const gchar* value);
>   gchar** virt_viewer_file_get_secure_channels(VirtViewerFile* self, gsize* length);
>   void virt_viewer_file_set_secure_channels(VirtViewerFile* self, const gchar* const* value, gsize length);
> +gint virt_viewer_file_get_delete_this_file(VirtViewerFile* self);
> +void virt_viewer_file_set_delete_this_file(VirtViewerFile* self, gint value);
>
>   G_END_DECLS
>
>




More information about the virt-tools-list mailing list