From 96f9f8134a84f2254a3f01fe17db07de9ee02a33 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Mon, 4 Jul 2022 12:58:22 -0400 Subject: [PATCH] Disable selection of the btrfs backend when there are no btrfs filesystems found. The old check was for the presence of the 'btrfs' command, whose package was a dependency of timeshift. --- src/Gtk/SnapshotBackendBox.vala | 56 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Gtk/SnapshotBackendBox.vala b/src/Gtk/SnapshotBackendBox.vala index 09bbd0f..9df9191 100755 --- a/src/Gtk/SnapshotBackendBox.vala +++ b/src/Gtk/SnapshotBackendBox.vala @@ -97,37 +97,45 @@ class SnapshotBackendBox : Gtk.Box{ hbox.add (opt); opt_btrfs = opt; + if (!check_for_btrfs_tools()) { + opt.sensitive = false; + opt_rsync.active = true; + } + opt_btrfs.toggled.connect(()=>{ if (opt_btrfs.active){ - if (check_for_btrfs_tools()){ - App.btrfs_mode = true; - init_backend(); - type_changed(); - update_description(); - } - else{ - opt_rsync.active = true; - } + App.btrfs_mode = true; + init_backend(); + type_changed(); + update_description(); } }); } - private bool check_for_btrfs_tools(){ - - if (!cmd_exists("btrfs")){ - - string msg = _("The 'btrfs' command is not available on your system. Install the 'btrfs-tools' package and try again."); - string title = _("BTRFS Tools Not Found"); - gtk_set_busy(false, parent_window); - gtk_messagebox(title, msg, parent_window, true); - - return false; - } - else{ - return true; - } + private bool check_for_btrfs_tools() { + try { + const string args[] = {"lsblk", "-o", "FSTYPE", null}; + var proc = new Subprocess.newv( + args, + SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_SILENCE + ); + + Bytes stdout; + if (proc.communicate(null, null, out stdout, null)) { + string output = (string) Bytes.unref_to_data(stdout); + + if (output.contains("btrfs")) { + return true; + } + } + } + catch (Error e) { + log_error (e.message); + } + + return false; } - + private void add_description(){ Gtk.Expander expander = new Gtk.Expander(_("Help"));