From f28cc892843ec4ee18f14d911e92bf729a855ca2 Mon Sep 17 00:00:00 2001 From: tkashkin Date: Mon, 29 Jul 2019 19:58:36 +0300 Subject: [PATCH] Add `/opt/` and `/var/opt/` to FSOverlay allowed paths list (#290) Wait for overlays to mount before updating game status (#291) --- src/data/Game.vala | 8 ++++---- src/data/sources/gog/GOGGame.vala | 4 ++-- src/data/sources/humble/HumbleGame.vala | 2 +- src/data/sources/user/UserGame.vala | 2 +- src/ui/dialogs/GameFSOverlaysDialog.vala | 2 +- src/utils/FSOverlay.vala | 14 +++++++++++++- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/data/Game.vala b/src/data/Game.vala index 609a3351..e2590335 100644 --- a/src/data/Game.vala +++ b/src/data/Game.vala @@ -245,7 +245,7 @@ namespace GameHub.Data dirs += install_dir.get_child(FSUtils.GAMEHUB_DIR).get_child(Overlay.BASE); } dirs += install_dir; - mount_overlays(); + mount_overlays.begin(); } foreach(var dir in dirs) { @@ -395,7 +395,7 @@ namespace GameHub.Data } } - public void mount_overlays(File? persist=null) + public async void mount_overlays(File? persist=null) { if(!overlays_enabled) return; load_overlays(); @@ -418,9 +418,9 @@ namespace GameHub.Data fs_overlay = new FSOverlay(merged_dir, dirs, persist_dir, work_dir); if(fs_overlay.options != fs_overlay_last_options) { - fs_overlay.mount.begin(); + fs_overlay_last_options = fs_overlay.options; + yield fs_overlay.mount(); } - fs_overlay_last_options = fs_overlay.options; } public async void umount_overlays() diff --git a/src/data/sources/gog/GOGGame.vala b/src/data/sources/gog/GOGGame.vala index 10e9f243..730a58ca 100644 --- a/src/data/sources/gog/GOGGame.vala +++ b/src/data/sources/gog/GOGGame.vala @@ -147,7 +147,7 @@ namespace GameHub.Data.Sources.GOG update_status(); - mount_overlays(); + yield mount_overlays(); if(info_detailed == null || info_detailed.length == 0) { @@ -964,7 +964,7 @@ namespace GameHub.Data.Sources.GOG game.overlays.add(dlc_overlay); game.save_overlays(); - game.mount_overlays(); + yield game.mount_overlays(); } } } diff --git a/src/data/sources/humble/HumbleGame.vala b/src/data/sources/humble/HumbleGame.vala index 0ad683a6..b50856f5 100644 --- a/src/data/sources/humble/HumbleGame.vala +++ b/src/data/sources/humble/HumbleGame.vala @@ -183,7 +183,7 @@ namespace GameHub.Data.Sources.Humble update_status(); - mount_overlays(); + yield mount_overlays(); if((icon == null || icon == "") && (info != null && info.length > 0)) { diff --git a/src/data/sources/user/UserGame.vala b/src/data/sources/user/UserGame.vala index 3335e675..b6f9d618 100644 --- a/src/data/sources/user/UserGame.vala +++ b/src/data/sources/user/UserGame.vala @@ -117,7 +117,7 @@ namespace GameHub.Data.Sources.User { update_status(); - mount_overlays(); + yield mount_overlays(); if(installer == null && info != null && info.length > 0) { diff --git a/src/ui/dialogs/GameFSOverlaysDialog.vala b/src/ui/dialogs/GameFSOverlaysDialog.vala index 35270da0..1261d1db 100644 --- a/src/ui/dialogs/GameFSOverlaysDialog.vala +++ b/src/ui/dialogs/GameFSOverlaysDialog.vala @@ -139,7 +139,7 @@ namespace GameHub.UI.Dialogs destroy.connect(() => { game.save_overlays(); - game.mount_overlays(); + game.mount_overlays.begin(); }); show_all(); diff --git a/src/utils/FSOverlay.vala b/src/utils/FSOverlay.vala index 305b60c0..974d24f8 100644 --- a/src/utils/FSOverlay.vala +++ b/src/utils/FSOverlay.vala @@ -154,12 +154,24 @@ namespace GameHub.Utils { SAFE, UNSAFE, RESTRICTED; + private const string[] ALLOWED_PATHS = { "/home/", "/mnt/", "/media/", "/run/media/", "/opt/", "/var/opt/" }; + public static RootPathSafety for(File? root) { if(root == null || !root.query_exists()) return RESTRICTED; var path = root.get_path().down(); - if(!path.has_prefix("/home/") && !path.has_prefix("/mnt/") && !path.has_prefix("/media/") && !path.has_prefix("/run/media/")) + var allowed = false; + foreach(var prefix in ALLOWED_PATHS) + { + if(path.has_prefix(prefix)) + { + allowed = true; + break; + } + } + + if(!allowed) { return RESTRICTED; }