[gnome-chess/gnome-3-38] Never open file chooser to /run



commit 5def372e57dd55d0e099c06d39711a114486e18f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Dec 6 09:15:07 2020 -0600

    Never open file chooser to /run
    
    If we are sandboxed, then any files we save are going to be located
    under /run inside the sandbox. But that's not where they are on the host
    system, so we should try to avoid exposing this to the user. Sad reality
    is that there is no way we can know where the file really exists on the
    host, so let's just not preselect the file's location in this case.
    
    Fixes #53

 src/gnome-chess.vala | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index bb91f32..b409800 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -2309,11 +2309,30 @@ Copyright © 2015–2016 Sahil Sareen""";
                                                  _("_Save"),
                                                  _("_Cancel"));
 
-            if (game_file != null && game_file.get_path () != autosave_filename)
-                save_dialog.set_filename (game_file.get_path ());
-            else
+            var set_filename = false;
+            if (game_file != null)
+            {
+                /* If the path is under /run, we are probably sandboxed, and the
+                 * path we see is entirely different from the path to the file
+                 * on the host system. In this case, we should force the user to
+                 * navigate the filesystem rather than displaying /run, which
+                 * would be meaningless to the user.
+                 *
+                 * Also, of course we don't want to preselect the autosave file.
+                 */
+                var path = game_file.get_path ();
+                if (path != autosave_filename && !path.has_prefix ("/run"))
+                {
+                    save_dialog.set_filename (path);
+                    set_filename = true;
+                }
+            }
+
+            if (!set_filename)
+            {
                 save_dialog.set_current_name (/* Default filename for the save game dialog */
                                               _("Untitled Chess Game") + ".pgn");
+            }
 
             /* Filter out non PGN files by default */
             var pgn_filter = new FileFilter ();


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