[gnome-boxes] downloader: Separate out fetching of cached file



commit 41e89aac65fef7a867736fd82c638231208a79d8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Oct 2 01:03:12 2014 +0100

    downloader: Separate out fetching of cached file
    
    Split out fetching of cached file code into a separate private method.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=738016

 src/downloader.vala |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/src/downloader.vala b/src/downloader.vala
index 82867da..77e431c 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -79,14 +79,9 @@ private class Boxes.Downloader : GLib.Object {
             // Already being downloaded
             return yield await_download (download, cached_path, progress);
 
-        GLib.File cached_file;
-        foreach (var path in cached_paths) {
-            cached_file = File.new_for_path (path);
-            if (cached_file.query_exists ()) {
-                debug ("'%s' already available locally at '%s'. Not downloading.", uri, path);
-                return cached_file;
-            }
-        }
+        var cached_file = get_cached_file (remote_file, cached_paths);
+        if (cached_file != null)
+            return cached_file;
 
         cached_file = GLib.File.new_for_path (cached_path);
         debug ("Downloading '%s'...", uri);
@@ -271,4 +266,16 @@ private class Boxes.Downloader : GLib.Object {
             debug ("Copied '%s' to '%s'.", src_file.get_path (), dest_file.get_path ());
         } catch (IOError.EXISTS error) {}
     }
+
+    private File? get_cached_file (File remote_file, string[] cached_paths) {
+        foreach (var path in cached_paths) {
+            var cached_file = File.new_for_path (path);
+            if (cached_file.query_exists ()) {
+                debug ("'%s' already available locally at '%s'. Not downloading.", remote_file.get_uri (), 
path);
+                return cached_file;
+            }
+        }
+
+        return null;
+    }
 }


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