~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Core/Main.vala

  • Committer: Tony George
  • Date: 2016-11-01 12:07:45 UTC
  • Revision ID: tony.george.kol@gmail.com-20161101120745-rqdl2p6125cgp428
RestoreWindow: Fixed some issues in device selection logic; Comboboxes would remain unselected in some scenarios; User will be prompted to unlock default devices before the restore window is displayed;

Show diffs side-by-side

added added

removed removed

Lines of Context:
1372
1372
                bool home_found = false;
1373
1373
                dst_root = null;
1374
1374
                
1375
 
                foreach(var mnt in fstab_list){
 
1375
                foreach(var fs_entry in fstab_list){
1376
1376
 
1377
1377
                        // skip mounting for non-system devices
1378
1378
                        
1379
 
                        if (!mnt.is_for_system_directory()){
 
1379
                        if (!fs_entry.is_for_system_directory()){
1380
1380
                                continue;
1381
1381
                        }
1382
1382
 
1383
1383
                        // find device by name or uuid
1384
1384
                        
1385
 
                        Device mnt_dev = null;
1386
 
                        if (mnt.device_uuid.length > 0){
1387
 
                                mnt_dev = Device.get_device_by_uuid(mnt.device_uuid);
 
1385
                        Device dev_fstab = null;
 
1386
                        if (fs_entry.device_uuid.length > 0){
 
1387
                                dev_fstab = Device.get_device_by_uuid(fs_entry.device_uuid);
1388
1388
                        }
1389
1389
                        else{
1390
 
                                mnt_dev = Device.get_device_by_name(mnt.device);
 
1390
                                dev_fstab = Device.get_device_by_name(fs_entry.device_string);
1391
1391
                        }
1392
1392
 
1393
 
                        // replace mapped name with parent device
 
1393
                        if (dev_fstab == null){
1394
1394
 
1395
 
                        if (mnt_dev == null){
1396
 
                                
1397
1395
                                /*
1398
 
                                Note: This is required since the mapped name may be different on running system.
1399
 
                                Since we don't have the same mapped name, we cannot resolve the device without
1400
 
                                identifying the parent partition
 
1396
                                Check if the device mentioned in fstab entry is a mapped device.
 
1397
                                If it is, then try finding the parent device which may be available on the current system.
 
1398
                                Prompt user to unlock it if found.
 
1399
                                
 
1400
                                Note:
 
1401
                                Mapped name may be different on running system, or it may be same.
 
1402
                                Since it is not reliable, we will try to identify the parent intead of the mapped device.
1401
1403
                                */
1402
 
 
1403
 
                                if (mnt.device.has_prefix("/dev/mapper/")){
1404
 
                                        string mapped_name = mnt.device.replace("/dev/mapper/","");
1405
 
                                        foreach(var entry in crypttab_list){
1406
 
                                                if (entry.mapped_name == mapped_name){
1407
 
                                                        mnt.device = entry.device;
 
1404
                                
 
1405
                                if (fs_entry.device_string.has_prefix("/dev/mapper/")){
 
1406
                                        
 
1407
                                        string mapped_name = fs_entry.device_string.replace("/dev/mapper/","");
 
1408
                                        
 
1409
                                        foreach(var crypt_entry in crypttab_list){
 
1410
                                                
 
1411
                                                if (crypt_entry.mapped_name == mapped_name){
 
1412
 
 
1413
                                                        // we found the entry for the mapped device
 
1414
                                                        fs_entry.device_string = crypt_entry.device_string;
 
1415
 
 
1416
                                                        if (fs_entry.device_uuid.length > 0){
 
1417
                                                                
 
1418
                                                                // we have the parent's uuid. get the luks device and prompt user to unlock it.
 
1419
                                                                var dev_luks = Device.get_device_by_uuid(fs_entry.device_uuid);
 
1420
                                                                
 
1421
                                                                if (dev_luks != null){
 
1422
                                                                        
 
1423
                                                                        string msg_out, msg_err;
 
1424
                                                                        var dev_unlocked = Device.luks_unlock(
 
1425
                                                                                dev_luks, "", "", parent_window, out msg_out, out msg_err);
 
1426
 
 
1427
                                                                        if (dev_unlocked != null){
 
1428
                                                                                dev_fstab = dev_unlocked;
 
1429
                                                                                update_partitions();
 
1430
                                                                        }
 
1431
                                                                        else{
 
1432
                                                                                dev_fstab = dev_luks; // map to parent
 
1433
                                                                        }
 
1434
                                                                }
 
1435
                                                        }
 
1436
                                                        else{
 
1437
                                                                // nothing to do: we don't have the parent's uuid
 
1438
                                                        }
 
1439
 
1408
1440
                                                        break;
1409
1441
                                                }
1410
1442
                                        }
1411
1443
                                }
1412
 
 
1413
 
                                // try again - find device by name or uuid
1414
 
                        
1415
 
                                if (mnt.device_uuid.length > 0){
1416
 
                                        mnt_dev = Device.get_device_by_uuid(mnt.device_uuid);
1417
 
                                }
1418
 
                                else{
1419
 
                                        mnt_dev = Device.get_device_by_name(mnt.device);
1420
 
                                }
1421
1444
                        }
1422
1445
 
1423
 
                        if (mnt_dev != null){
 
1446
                        if (dev_fstab != null){
1424
1447
                                
1425
1448
                                log_debug("added: dev: %s, path: %s, options: %s".printf(
1426
 
                                        mnt_dev.device, mnt.mount_point, mnt.options));
 
1449
                                        dev_fstab.device, fs_entry.mount_point, fs_entry.options));
1427
1450
                                        
1428
 
                                mount_list.add(new MountEntry(mnt_dev, mnt.mount_point, mnt.options));
 
1451
                                mount_list.add(new MountEntry(dev_fstab, fs_entry.mount_point, fs_entry.options));
1429
1452
                                
1430
 
                                if (mnt.mount_point == "/"){
1431
 
                                        dst_root = mnt_dev;
 
1453
                                if (fs_entry.mount_point == "/"){
 
1454
                                        dst_root = dev_fstab;
1432
1455
                                }
1433
1456
                        }
1434
1457
                        else{
1435
1458
                                log_debug("missing: dev: %s, path: %s, options: %s".printf(
1436
 
                                        mnt.device, mnt.mount_point, mnt.options));
 
1459
                                        fs_entry.device_string, fs_entry.mount_point, fs_entry.options));
1437
1460
 
1438
 
                                mount_list.add(new MountEntry(null, mnt.mount_point, mnt.options));
 
1461
                                mount_list.add(new MountEntry(null, fs_entry.mount_point, fs_entry.options));
1439
1462
                        }
1440
1463
 
1441
 
                        if (mnt.mount_point == "/"){
 
1464
                        if (fs_entry.mount_point == "/"){
1442
1465
                                root_found = true;
1443
1466
                        }
1444
 
                        if (mnt.mount_point == "/boot"){
 
1467
                        if (fs_entry.mount_point == "/boot"){
1445
1468
                                boot_found = true;
1446
1469
                        }
1447
 
                        if (mnt.mount_point == "/home"){
 
1470
                        if (fs_entry.mount_point == "/home"){
1448
1471
                                home_found = true;
1449
1472
                        }
1450
1473
                }
1451
1474
 
1452
1475
                if (!root_found){
 
1476
                        log_debug("added null entry: /");
1453
1477
                        mount_list.add(new MountEntry(null, "/", "")); // add root entry
1454
1478
                }
1455
1479
 
1456
1480
                if (!boot_found){
 
1481
                        log_debug("added null entry: /boot");
1457
1482
                        mount_list.add(new MountEntry(null, "/boot", "")); // add boot entry
1458
1483
                }
1459
1484
 
1460
1485
                if (!home_found){
 
1486
                        log_debug("added null entry: /home");
1461
1487
                        mount_list.add(new MountEntry(null, "/home", "")); // add home entry
1462
1488
                }
1463
1489
 
2068
2094
                        }
2069
2095
 
2070
2096
                        //update fstab entry
2071
 
                        entry.device = "UUID=%s".printf(mnt.device.uuid);
 
2097
                        entry.device_string = "UUID=%s".printf(mnt.device.uuid);
2072
2098
                        entry.type = mnt.device.fstype;
2073
2099
 
2074
2100
                        // fix mount options for non-btrfs device
2551
2577
                        // unlock encrypted device
2552
2578
                        if (mnt.device.is_encrypted_partition()){
2553
2579
 
2554
 
                                string msg_out, msg_err;
2555
 
                
2556
 
                                mnt.device = Device.luks_unlock(
2557
 
                                        mnt.device, "", "", parent_win, out msg_out, out msg_err);
 
2580
                                // check if unlocked
 
2581
                                if (mnt.device.has_children()){
 
2582
                                        mnt.device = mnt.device.children[0];
 
2583
                                }
 
2584
                                else{
 
2585
                                        // prompt user
 
2586
                                        string msg_out, msg_err;
 
2587
                        
 
2588
                                        var dev_unlocked = Device.luks_unlock(
 
2589
                                                mnt.device, "", "", parent_win, out msg_out, out msg_err);
2558
2590
 
2559
 
                                //exit if not found
2560
 
                                if (mnt.device == null){
2561
 
                                        return false;
 
2591
                                        //exit if not found
 
2592
                                        if (dev_unlocked == null){
 
2593
                                                return false;
 
2594
                                        }
 
2595
                                        else{
 
2596
                                                mnt.device = dev_unlocked;
 
2597
                                        }
2562
2598
                                }
2563
2599
                        }
2564
2600