[gnome-boxes/wip/rishi/rhel: 8/14] downloader, wizard: Support a custom filename for downloaded media



commit 766a8ad26bb444ee893056d15926f45049dce2e7
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Aug 31 20:24:35 2017 +0200

    downloader, wizard: Support a custom filename for downloaded media
    
    The URI for getting gratis RHEL ISOs from the Red Hat developer portal
    at developers.redhat.com looks like this:
      https://access.cdn.redhat.com/.../rhel...dvd.iso?_auth_=......
    
    While it seems possible to get the basename of the downloaded file by
    removing the URI's query string, there is no guarantee that the
    structure of the URI won't change in future.
    
    On the other hand, the basename of the downloaded ISO is encoded in the
    authentication URI that's embedded in the initial JSON or XML response
    from the server. It might be better to use that instead. Therefore,
    there is a need to explicitly specify the filename.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786679

 src/downloader.vala |   10 +++++++++-
 src/wizard.vala     |    2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/downloader.vala b/src/downloader.vala
index 86fac3b..6ca8251 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -205,10 +205,18 @@ private class Boxes.Downloader : GLib.Object {
     }
 
     public static async string fetch_media (string           uri,
+                                            string?          filename = null,
                                             ActivityProgress progress = new ActivityProgress (),
                                             Cancellable?     cancellable = null) throws GLib.Error {
         var file = File.new_for_uri (uri);
-        var basename = file.get_basename ();
+        string? basename = null;
+
+        if (filename == null) {
+            basename = file.get_basename ();
+        } else {
+            basename = filename;
+        }
+
         return_val_if_fail (basename != null && basename != "" && basename != "/", null);
 
         var downloader = Downloader.get_instance ();
diff --git a/src/wizard.vala b/src/wizard.vala
index 6001e44..6be2980 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -602,7 +602,7 @@ private class Boxes.Wizard: Gtk.Stack, Boxes.UI {
         prep_status_label.label = _("Downloading media…");
 
         try {
-            var cache_path = yield Downloader.fetch_media (uri, download_progress, prepare_cancellable);
+            var cache_path = yield Downloader.fetch_media (uri, null, download_progress, 
prepare_cancellable);
             prepare_downloaded_media (cache_path, progress);
         } catch (GLib.IOError.CANCELLED e) {
             debug ("Cancelled downloading media '%s'!", uri);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]