Skip to content
This repository has been archived by the owner on Oct 16, 2022. It is now read-only.

Added support for writable loop devices and LVM #315

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public class Main : GLib.Object{

log_debug("Main: check_dependencies()");

string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync"}; //"shutdown","chroot",
string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync","ionice"}; //"shutdown","chroot",

string path;
foreach(string cmd_tool in dependencies){
Expand Down Expand Up @@ -2249,7 +2249,7 @@ public class Main : GLib.Object{

// run rsync ---------------------------------------

sh += "rsync -avir --force --delete --delete-after";
sh += "ionice -c idle rsync -avir --force --delete --delete-after";

if (dry_run){
sh += " --dry-run";
Expand Down Expand Up @@ -3328,12 +3328,29 @@ public class Main : GLib.Object{
sys_home = null;

foreach(var pi in partitions){
if ((app_mode == "")||(LOG_DEBUG)){
log_debug("Partition \"%s\" on device \"%s\" : read-only = %s.".printf(
pi.name,
pi.device,
pi.read_only.to_string()
));
}

if ( pi.read_only ) {
continue;
}

foreach(var mp in pi.mount_points){

// skip loop devices - Fedora Live uses loop devices containing ext4-formatted lvm volumes
if ((pi.type == "loop") || (pi.has_parent() && (pi.parent.type == "loop"))){
continue;
if ((app_mode == "")||(LOG_DEBUG)){
log_debug("Mount point \"%s\" : read-only = %s.".printf(mp.mount_point, mp.read_only.to_string()));
}

if ( mp.read_only ) {
continue;
}
}

if (mp.mount_point == "/"){
Expand Down
4 changes: 2 additions & 2 deletions src/Core/SnapshotRepo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ public class SnapshotRepo : GLib.Object{
try{
var f = File.new_for_path(thr_args1);
if(f.query_exists()){
cmd = "rm -rf \"%s\"".printf(thr_args1);
cmd = "ionice -c idle rm -rf \"%s\"".printf(thr_args1);

if (LOG_COMMANDS) { log_debug(cmd); }

Expand Down Expand Up @@ -1039,7 +1039,7 @@ public class SnapshotRepo : GLib.Object{
string path = "%s-%s".printf(snapshots_path, tag);
var f = File.new_for_path(path);
if (f.query_exists()){
cmd = "rm -rf \"%s\"".printf(path + "/");
cmd = "ionice -c idle rm -rf \"%s\"".printf(path + "/");

if (LOG_COMMANDS) { log_debug(cmd); }

Expand Down
50 changes: 35 additions & 15 deletions src/Gtk/BackupDeviceBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class BackupDeviceBox : Gtk.Box{
Device dev;
model.get (iter, 0, out dev, -1);

(cell as Gtk.CellRendererPixbuf).visible = (dev.type == "disk");

(cell as Gtk.CellRendererPixbuf).visible = ((dev.type == "disk") || (dev.type == "lvm"));
});

col.add_attribute(cell_pix, "icon-name", 2);
Expand All @@ -147,7 +146,10 @@ class BackupDeviceBox : Gtk.Box{
(cell as Gtk.CellRendererToggle).active = selected;

(cell as Gtk.CellRendererToggle).visible =
(dev.size_bytes > 10 * KB) && (dev.type != "disk") && (dev.children.size == 0);
(dev.size_bytes > 10 * KB) && (
((dev.type != "disk") && (dev.children.size == 0)) ||
(dev.type != "lvm")
);
});

//cell_radio.toggled.connect((path)=>{});
Expand All @@ -170,21 +172,33 @@ class BackupDeviceBox : Gtk.Box{
(cell as Gtk.CellRendererText).text = dev.description_full_free();
}*/

if (dev.type == "disk"){
if (
(dev.type == "disk") ||
(dev.type == "lvm")
)
{
var txt = "%s %s".printf(dev.model, dev.vendor).strip();
if (txt.length == 0){
txt = "%s Disk".printf(format_file_size(dev.size_bytes));
txt = dev.name;
}

(cell as Gtk.CellRendererText).text = txt.strip();
}
else {
(cell as Gtk.CellRendererText).text = dev.kname;
}

//(cell as Gtk.CellRendererText).sensitive = (dev.type != "disk");
});

// UUID

col = add_column_text(tv_devices, _("UUID"), out cell_text);

col.set_cell_data_func(cell_text, (cell_layout, cell, model, iter)=>{
Device dev;
model.get (iter, 0, out dev, -1);
(cell as Gtk.CellRendererText).text = dev.uuid;
});

// type

col = add_column_text(tv_devices, _("Type"), out cell_text);
Expand Down Expand Up @@ -227,7 +241,7 @@ class BackupDeviceBox : Gtk.Box{
(dev.free_bytes > 0) ? format_file_size(dev.free_bytes, false, "", true, 0) : "";
}

(cell as Gtk.CellRendererText).sensitive = (dev.type != "disk");
(cell as Gtk.CellRendererText).sensitive = ((dev.type != "disk") || (dev.type != "lvm"));
});

// name
Expand All @@ -246,7 +260,7 @@ class BackupDeviceBox : Gtk.Box{
(cell as Gtk.CellRendererText).text = dev.partlabel;
}

(cell as Gtk.CellRendererText).sensitive = (dev.type != "disk");
(cell as Gtk.CellRendererText).sensitive = ((dev.type != "disk") || (dev.type != "lvm"));
});

// label
Expand All @@ -265,7 +279,7 @@ class BackupDeviceBox : Gtk.Box{
(cell as Gtk.CellRendererText).text = dev.label;
}

(cell as Gtk.CellRendererText).sensitive = (dev.type != "disk");
(cell as Gtk.CellRendererText).sensitive = ((dev.type != "disk") || (dev.type != "lvm"));
});

// buffer
Expand Down Expand Up @@ -354,8 +368,11 @@ class BackupDeviceBox : Gtk.Box{
private void try_change_device(Device dev){

log_debug("try_change_device: %s".printf(dev.device));

if (dev.type == "disk"){

if (
(dev.type == "disk") ||
(dev.type == "lvm")
) {

bool found_child = false;

Expand Down Expand Up @@ -588,8 +605,11 @@ class BackupDeviceBox : Gtk.Box{
TreeIter iter0;

foreach(var disk in App.partitions) {

if (disk.type != "disk") { continue; }
if (
(disk.type != "disk") &&
(disk.type != "lvm" )
)
{ continue; }

model.append(out iter0, null);
model.set(iter0, 0, disk, -1);
Expand Down Expand Up @@ -648,7 +668,7 @@ class BackupDeviceBox : Gtk.Box{

tv_append_child_volumes(ref model, ref iter1, part);
}
else if ((part.kname == parent.kname) && (part.type == "disk")
else if ((part.kname == parent.kname) && ((part.type == "disk") || (part.type == "lvm"))
&& part.has_linux_filesystem() && !part.has_children()){

// partition-less disk with linux filesystem
Expand Down
2 changes: 1 addition & 1 deletion src/Gtk/SettingsWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SettingsWindow : Gtk.Window{
private UsersBox users_box;

private uint tmr_init;
private int def_width = 500;
private int def_width = 640;
private int def_height = 500;

public SettingsWindow() {
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/AsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public class RsyncTask : AsyncTask{
private string build_script() {
var script = new StringBuilder();

var cmd = "rsync -ai";
var cmd = "ionice -c idle rsync -ai";

if (verbose){
cmd += " --verbose";
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/DeleteFileTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class DeleteFileTask : AsyncTask{

if (use_rsync){

cmd += "rsync -aii";
cmd += "ionice -c idle rsync -aii";

if (verbose){
cmd += " --verbose";
Expand All @@ -113,7 +113,7 @@ public class DeleteFileTask : AsyncTask{
cmd += " '%s/'".printf(escape_single_quote(dest_path));
}
else{
cmd += "rm";
cmd += "ionice -c idle rm";

if (verbose){
cmd += " -rfv";
Expand Down
14 changes: 14 additions & 0 deletions src/Utility/Device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public class Device : GLib.Object{
test_lsblk_version();

var list = new Gee.ArrayList<Device>();
var knames_check_list = new Gee.HashSet<string>();

string std_out;
string std_err;
Expand Down Expand Up @@ -441,6 +442,19 @@ public class Device : GLib.Object{

pi.name = match.fetch(++pos).strip();
pi.kname = match.fetch(++pos).strip();

if ( knames_check_list.contains(pi.kname) ) {
if (LOG_DEBUG) {
log_debug("Device \"%s\" with same kname \"%s\" already added.".printf(
pi.name,
pi.kname
));
}

continue;
} else {
knames_check_list.add(pi.kname);
}

pi.label = match.fetch(++pos); // don't strip; labels can have leading or trailing spaces
pi.uuid = match.fetch(++pos).strip();
Expand Down
13 changes: 13 additions & 0 deletions src/Utility/MountEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ public class MountEntry : GLib.Object{
public Device device = null;
public string mount_point = "";
public string mount_options = "";
public bool read_only = false;

public MountEntry(Device? device, string mount_point, string mount_options){
this.device = device;
this.mount_point = mount_point;
this.mount_options = mount_options;

foreach (string option in mount_options.split(",")) {
option = option.strip();

if ("ro" == option) {
this.read_only = true;
break;
} else if ("rw" == option) {
this.read_only = false;
break;
}
}
}

public string subvolume_name(){
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/RsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public class RsyncTask : AsyncTask{
//cmd += "ionice -c2 -n7 ";
}

cmd += "rsync -aii";
cmd += "ionice -c idle rsync -aii";

//if (!dry_run){
// cmd += "i";
Expand Down
10 changes: 5 additions & 5 deletions src/Utility/TeeJee.FileSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ namespace TeeJee.FileSystem{
return true;
}

string cmd = "rm -rf '%s'".printf(escape_single_quote(dir_path));
string cmd = "ionice -c idle rm -rf '%s'".printf(escape_single_quote(dir_path));
log_debug(cmd);
string std_out, std_err;
int status = exec_sync(cmd, out std_out, out std_err);
Expand Down Expand Up @@ -619,7 +619,7 @@ namespace TeeJee.FileSystem{
escape_single_quote(dst_file),
escape_single_quote(tar_file));

cmd += "rm -f '%s'\n".printf(escape_single_quote(tar_file));
cmd += "ionice -c idle rm -f '%s'\n".printf(escape_single_quote(tar_file));

log_debug(cmd);

Expand Down Expand Up @@ -689,7 +689,7 @@ namespace TeeJee.FileSystem{
string cmd = "";

// gpg cannot overwrite - remove tar file if it exists
cmd += "rm -f '%s'\n".printf(escape_single_quote(tar_file));
cmd += "ionice -c idle rm -f '%s'\n".printf(escape_single_quote(tar_file));

cmd += "gpg --passphrase '%s' -o '%s' --decrypt '%s'\n".printf(
password,
Expand All @@ -702,7 +702,7 @@ namespace TeeJee.FileSystem{
escape_single_quote(tar_file),
escape_single_quote(file_parent(dst_file)));

cmd += "rm -f '%s'\n".printf(escape_single_quote(tar_file));
cmd += "ionice -c idle rm -f '%s'\n".printf(escape_single_quote(tar_file));

log_debug(cmd);

Expand Down Expand Up @@ -834,7 +834,7 @@ namespace TeeJee.FileSystem{

/* Sync files with rsync */

string cmd = "rsync -avh";
string cmd = "ionice -c idle rsync -avh";
cmd += updateExisting ? "" : " --ignore-existing";
cmd += deleteExtra ? " --delete" : "";
cmd += " '%s'".printf(escape_single_quote(sourceDirectory) + "//");
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/TeeJee.Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace TeeJee.ProcessHelper{
exec_script_sync("echo 'ok'",out std_out,out std_err, true);
if ((std_out == null)||(std_out.strip() != "ok")){
TEMP_DIR = Environment.get_home_dir() + "/.temp/" + subdir_name + "/" + random_string();
exec_sync("rm -rf '%s'".printf(TEMP_DIR), null, null);
exec_sync("ionice -c idle rm -rf '%s'".printf(TEMP_DIR), null, null);
dir_create(TEMP_DIR);
}

Expand Down