mirror of
https://github.com/linuxmint/timeshift.git
synced 2024-09-11 17:07:43 +03:00
Improved error handling for mounting backup device
This commit is contained in:
parent
03e5110971
commit
715138faf2
106
src/Main.vala
106
src/Main.vala
@ -1550,7 +1550,16 @@ public class Main : GLib.Object{
|
||||
string target_path = "/"; //current system root
|
||||
|
||||
if (!restore_current_system){
|
||||
mount_target_device();
|
||||
|
||||
bool status = mount_target_device();
|
||||
|
||||
if (status == false){
|
||||
log_error ("Failed to mount target device");
|
||||
is_success = false;
|
||||
in_progress = false;
|
||||
return;
|
||||
}
|
||||
|
||||
target_path = mount_point_restore;
|
||||
|
||||
//check BTRFS volume
|
||||
@ -1882,6 +1891,7 @@ public class Main : GLib.Object{
|
||||
var config = node.get_object();
|
||||
|
||||
string uuid = json_get_string(config,"backup_device_uuid","");
|
||||
|
||||
foreach(PartitionInfo pi in partition_list){
|
||||
if (pi.uuid == uuid){
|
||||
snapshot_device = pi;
|
||||
@ -1889,7 +1899,7 @@ public class Main : GLib.Object{
|
||||
}
|
||||
}
|
||||
|
||||
if (snapshot_device == null){
|
||||
if ((uuid.length == 0) || (snapshot_device == null)){
|
||||
log_msg (_("Warning: Backup device not set! Defaulting to system device"));
|
||||
snapshot_device = root_device;
|
||||
}
|
||||
@ -1938,39 +1948,40 @@ public class Main : GLib.Object{
|
||||
|
||||
string path = mount_point_backup + "/timeshift/snapshots";
|
||||
|
||||
if (dir_exists(path)){
|
||||
if (!dir_exists(path)){
|
||||
return false;
|
||||
}
|
||||
|
||||
try{
|
||||
var dir = File.new_for_path (path);
|
||||
var enumerator = dir.enumerate_children ("*", 0);
|
||||
|
||||
var info = enumerator.next_file ();
|
||||
while (info != null) {
|
||||
if (info.get_file_type() == FileType.DIRECTORY) {
|
||||
if (info.get_name() != ".sync") {
|
||||
TimeShiftBackup bak = new TimeShiftBackup(path + "/" + info.get_name());
|
||||
try{
|
||||
var dir = File.new_for_path (path);
|
||||
var enumerator = dir.enumerate_children ("*", 0);
|
||||
|
||||
var info = enumerator.next_file ();
|
||||
while (info != null) {
|
||||
if (info.get_file_type() == FileType.DIRECTORY) {
|
||||
if (info.get_name() != ".sync") {
|
||||
TimeShiftBackup bak = new TimeShiftBackup(path + "/" + info.get_name());
|
||||
if (bak.is_valid){
|
||||
snapshot_list.add(bak);
|
||||
}
|
||||
}
|
||||
info = enumerator.next_file ();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Error e){
|
||||
log_error (e.message);
|
||||
info = enumerator.next_file ();
|
||||
}
|
||||
}
|
||||
|
||||
catch(Error e){
|
||||
log_error (e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
snapshot_list.sort((a,b) => {
|
||||
TimeShiftBackup t1 = (TimeShiftBackup) a;
|
||||
TimeShiftBackup t2 = (TimeShiftBackup) b;
|
||||
return t1.date.compare(t2.date);
|
||||
});
|
||||
|
||||
|
||||
log_debug(_("updated snapshot list"));
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void update_partition_list(){
|
||||
@ -2050,8 +2061,7 @@ public class Main : GLib.Object{
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
mount_device(backup_device, mount_point_backup, "");
|
||||
return true;
|
||||
return mount_device(backup_device, mount_point_backup, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2060,19 +2070,18 @@ public class Main : GLib.Object{
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
mount_device(restore_target, mount_point_restore, "");
|
||||
return true;
|
||||
return mount_device(restore_target, mount_point_restore, "");
|
||||
}
|
||||
}
|
||||
|
||||
public void mount_device(PartitionInfo dev, string mount_point, string mount_options){
|
||||
if (!mount(dev.device, mount_point, mount_options)){
|
||||
public bool mount_device(PartitionInfo dev, string mount_point, string mount_options){
|
||||
bool status = mount(dev.device, mount_point, mount_options);
|
||||
if (status == false){
|
||||
if (app_mode == ""){
|
||||
gtk_messagebox_show(_("Critical Error"), _("Failed to mount device!") + "\n" + _("Application will exit"));
|
||||
gtk_messagebox_show(_("Error"), _("Failed to mount device") + ": %s".printf(dev.device));
|
||||
}
|
||||
exit_app();
|
||||
exit(0);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public void unmount_backup_device(bool force = true){
|
||||
@ -2236,7 +2245,14 @@ public class Main : GLib.Object{
|
||||
|
||||
if (!live_system()){
|
||||
if (!backup_device_online()){
|
||||
message = _("Backup device not available!");
|
||||
|
||||
if (snapshot_device == null){
|
||||
message = _("Please select the backup device");
|
||||
}
|
||||
else{
|
||||
message = _("Backup device not available");
|
||||
}
|
||||
|
||||
status_code = -1;
|
||||
}
|
||||
else{
|
||||
@ -2422,6 +2438,7 @@ public class TimeShiftBackup : GLib.Object{
|
||||
public string description = "";
|
||||
public Gee.ArrayList<string> tags;
|
||||
public Gee.ArrayList<string> exclude_list;
|
||||
public bool is_valid = true;
|
||||
|
||||
public TimeShiftBackup(string dir_path){
|
||||
|
||||
@ -2483,6 +2500,7 @@ public class TimeShiftBackup : GLib.Object{
|
||||
|
||||
public void read_control_file(){
|
||||
string ctl_file = path + "/info.json";
|
||||
|
||||
var f = File.new_for_path(ctl_file);
|
||||
if (f.query_exists()) {
|
||||
var parser = new Json.Parser();
|
||||
@ -2494,6 +2512,12 @@ public class TimeShiftBackup : GLib.Object{
|
||||
var node = parser.get_root();
|
||||
var config = node.get_object();
|
||||
|
||||
|
||||
if ((node == null)||(config == null)){
|
||||
is_valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
string val = json_get_string(config,"created","");
|
||||
if (val.length > 0) {
|
||||
DateTime date_utc = new DateTime.from_unix_utc(int64.parse(val));
|
||||
@ -2506,18 +2530,28 @@ public class TimeShiftBackup : GLib.Object{
|
||||
description = json_get_string(config,"comments","");
|
||||
app_version = json_get_string(config,"app-version","");
|
||||
}
|
||||
else{
|
||||
is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void read_exclude_list(){
|
||||
string list_file = path + "/exclude.list";
|
||||
|
||||
exclude_list.clear();
|
||||
foreach(string path in read_file(list_file).split("\n")){
|
||||
path = path.strip();
|
||||
if (!exclude_list.contains(path) && path.length > 0){
|
||||
exclude_list.add(path);
|
||||
|
||||
var f = File.new_for_path(list_file);
|
||||
if (f.query_exists()) {
|
||||
foreach(string path in read_file(list_file).split("\n")){
|
||||
path = path.strip();
|
||||
if (!exclude_list.contains(path) && path.length > 0){
|
||||
exclude_list.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void update_control_file(){
|
||||
|
@ -88,6 +88,7 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
//other
|
||||
private PartitionInfo snapshot_device_original;
|
||||
private int cmb_backup_device_index_default = -1;
|
||||
|
||||
public MainWindow () {
|
||||
this.title = AppName + " v" + AppVersion + " by " + AppAuthor + " (" + "teejeetech.blogspot.in" + ")";
|
||||
@ -706,7 +707,7 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
int index = -1;
|
||||
int index_selected = -1;
|
||||
int index_default = -1;
|
||||
cmb_backup_device_index_default = -1;
|
||||
|
||||
foreach(PartitionInfo pi in App.partition_list) {
|
||||
|
||||
@ -717,7 +718,7 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
index++;
|
||||
if ((App.root_device != null) && (pi.device == App.root_device.device)){
|
||||
index_default = index;
|
||||
cmb_backup_device_index_default = index;
|
||||
}
|
||||
if ((App.snapshot_device != null) && (pi.device == App.snapshot_device.device)){
|
||||
index_selected = index;
|
||||
@ -727,8 +728,8 @@ class MainWindow : Gtk.Window{
|
||||
if (index_selected > -1){
|
||||
//ok
|
||||
}
|
||||
else if (index_default > -1){
|
||||
index_selected = index_default;
|
||||
else if (cmb_backup_device_index_default > -1){
|
||||
index_selected = cmb_backup_device_index_default;
|
||||
}
|
||||
else if (index > -1){
|
||||
index_selected = 0;
|
||||
@ -736,7 +737,7 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
cmb_backup_device.set_model (store);
|
||||
cmb_backup_device.active = index_selected;
|
||||
|
||||
|
||||
log_debug("cmb_backup_device refreshed");
|
||||
}
|
||||
|
||||
@ -763,11 +764,20 @@ class MainWindow : Gtk.Window{
|
||||
TreeModel model = (TreeModel) combo.model;
|
||||
model.get(iter, 0, out pi);
|
||||
|
||||
//try changing backup device ------------------
|
||||
|
||||
App.snapshot_device = pi;
|
||||
App.mount_backup_device();
|
||||
|
||||
bool status = App.mount_backup_device();
|
||||
|
||||
if (status == false){
|
||||
cmb_backup_device.active = cmb_backup_device_index_default;
|
||||
}
|
||||
|
||||
App.update_snapshot_list();
|
||||
|
||||
refresh_tv_backups();
|
||||
|
||||
check_status();
|
||||
|
||||
gtk_set_busy(false, this);
|
||||
@ -1234,7 +1244,12 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
switch(status_code){
|
||||
case -1:
|
||||
txt = _("Backup device is not mounted!");
|
||||
if (App.snapshot_device == null){
|
||||
txt = _("Please select the backup device");
|
||||
}
|
||||
else{
|
||||
txt = _("Backup device not available");
|
||||
}
|
||||
txt = "<span foreground=\"#8A0808\">" + txt + "</span>";
|
||||
lbl_backup_device_warning.label = txt;
|
||||
lbl_backup_device_warning.visible = true;
|
||||
@ -1249,8 +1264,8 @@ class MainWindow : Gtk.Window{
|
||||
|
||||
case 2:
|
||||
long required = App.calculate_size_of_first_snapshot();
|
||||
txt = _("Backup device does not have enough space!");
|
||||
txt += " %.1f GB ".printf(required/1024.0) + _("is needed for first snapshot.");
|
||||
txt = _("Backup device does not have enough space!") + " ";
|
||||
txt += _("First snapshot needs") + " %.1f GB".printf(required/1024.0);
|
||||
txt = "<span foreground=\"#8A0808\">" + txt + "</span>";
|
||||
lbl_backup_device_warning.label = txt;
|
||||
lbl_backup_device_warning.visible = true;
|
||||
|
@ -17,11 +17,11 @@ long_line_behaviour=1
|
||||
long_line_column=80
|
||||
|
||||
[files]
|
||||
current_page=3
|
||||
FILE_NAME_0=14343;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FMain.vala;0;4
|
||||
FILE_NAME_1=36154;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FMainWindow.vala;0;4
|
||||
FILE_NAME_2=14700;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FSettingsWindow.vala;0;4
|
||||
FILE_NAME_3=8145;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FRestoreWindow.vala;0;4
|
||||
current_page=1
|
||||
FILE_NAME_0=53670;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FMain.vala;0;4
|
||||
FILE_NAME_1=37513;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FMainWindow.vala;0;4
|
||||
FILE_NAME_2=14509;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FSettingsWindow.vala;0;4
|
||||
FILE_NAME_3=16588;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FRestoreWindow.vala;0;4
|
||||
FILE_NAME_4=28586;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FUtility.vala;0;4
|
||||
FILE_NAME_5=708;Make;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2Fmakefile;0;4
|
||||
FILE_NAME_6=813;Conf;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fdebian%2Fcontrol;0;4
|
||||
@ -29,7 +29,6 @@ FILE_NAME_7=221;None;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fdebian
|
||||
FILE_NAME_8=3838;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fsrc%2FExcludeMessageWindow.vala;0;4
|
||||
FILE_NAME_9=433;Sh;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Fbuild-release.sh;0;4
|
||||
FILE_NAME_10=363;Sh;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Ftimeshift%2Finstaller%2Finstall.sh;0;4
|
||||
FILE_NAME_11=9347;Vala;0;16;1;1;0;%2Fhome%2Fteejee%2Fprojects%2Fconky-manager%2Fsrc%2FMainWindow.vala;0;4
|
||||
|
||||
[VTE]
|
||||
last_dir=/home/teejee
|
||||
|
Loading…
Reference in New Issue
Block a user