[epiphany/mcatanzaro/downloads-dir] Downloads dir should always be ~/Downloads in flatpak



commit 6b1ce7049de3cd65b29c99ea5c83cb3cd8c0eb90
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Jan 7 22:51:52 2019 -0600

    Downloads dir should always be ~/Downloads in flatpak
    
    This was a mistake in 9d54c689. It doesn't make sense for the downloads
    directory to ever be ~/Desktop under flatpak, because it won't ever be
    writable. (I'm not sure why it passes on our CI; maybe the tests don't
    actually run inside the flatpak sandbox?) Better to just skip this test
    under flatpak.

 lib/ephy-file-helpers.c        | 20 +++++++++-----------
 tests/ephy-file-helpers-test.c |  2 +-
 2 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 65313b915..8784f308f 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -123,6 +123,8 @@ ephy_file_download_dir (void)
  * Returns a proper downloads destination by checking the
  * EPHY_PREFS_STATE_DOWNLOAD_DIR GSettings key and following this logic:
  *
+ *  - Under flatpak, always use the XDG downloads directory
+ *
  *  - An absolute path: considered user-set, use this value directly.
  *
  *  - "Desktop" keyword in GSettings: the directory returned by
@@ -136,24 +138,20 @@ ephy_file_download_dir (void)
 char *
 ephy_file_get_downloads_dir (void)
 {
-  char *download_dir;
+  g_autofree char *download_dir = g_settings_get_string (EPHY_SETTINGS_STATE,
+                                                         EPHY_PREFS_STATE_DOWNLOAD_DIR);
 
-  download_dir = g_settings_get_string (EPHY_SETTINGS_STATE,
-                                        EPHY_PREFS_STATE_DOWNLOAD_DIR);
+  if (ephy_is_running_inside_flatpak ())
+    return ephy_file_download_dir ();
 
-  if (g_strcmp0 (download_dir, "Desktop") == 0) {
-    g_free (download_dir);
+  if (g_strcmp0 (download_dir, "Desktop") == 0)
     return ephy_file_desktop_dir ();
-  }
 
   if (g_strcmp0 (download_dir, "Downloads") == 0 ||
-      !g_path_is_absolute (download_dir) ||
-      ephy_is_running_inside_flatpak ()) {
-    g_free (download_dir);
+      !g_path_is_absolute (download_dir))
     return ephy_file_download_dir ();
-  }
 
-  return download_dir;
+  return g_steal_pointer (&download_dir);
 }
 
 /**
diff --git a/tests/ephy-file-helpers-test.c b/tests/ephy-file-helpers-test.c
index 44e6880a7..558e1730b 100644
--- a/tests/ephy-file-helpers-test.c
+++ b/tests/ephy-file-helpers-test.c
@@ -108,7 +108,7 @@ typedef struct {
 
 static const DownloadsDirTest downloads_tests[] =
 {
-  { "Desktop", NULL, G_USER_DIRECTORY_DESKTOP, TRUE },
+  { "Desktop", NULL, G_USER_DIRECTORY_DESKTOP, FALSE },
 
   { "Downloads", NULL, G_USER_DIRECTORY_DOWNLOAD, TRUE },
   { "invalid-keyword", NULL, G_USER_DIRECTORY_DOWNLOAD, TRUE },


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