Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependencies to external binarys #333

Open
wants to merge 9 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
21 changes: 9 additions & 12 deletions src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public class Main : GLib.Object{
}

check_and_remove_timeshift_btrfs();

// init log ------------------

try {
Expand Down Expand Up @@ -3922,12 +3922,7 @@ public class Main : GLib.Object{
ret_val = exec_script_sync(cmd, out std_out, out std_err);
if (ret_val == 0){
required_space = long.parse(std_out.replace(",","").strip());

cmd = "wc -l '%s'".printf(escape_single_quote(file_log));
ret_val = exec_script_sync(cmd, out std_out, out std_err);
if (ret_val == 0){
file_count = long.parse(std_out.split(" ")[0].strip());
}
file_count = file_line_count(file_log) ?? 0;

thr_success = true;
}
Expand Down Expand Up @@ -4380,18 +4375,20 @@ public class Main : GLib.Object{

string cmd = "umount '%s'".printf(escape_single_quote(mdir2));
int retval = exec_sync(cmd);

string cmd2 = "rmdir '%s'".printf(escape_single_quote(mdir2));
int retval2 = exec_sync(cmd2);

if (retval2 != 0){

if (retval != 0){
log_debug("E: Failed to unmount");
log_debug("Ret=%d".printf(retval));
//ignore
}
else{
log_debug("Unmounted successfully");
}

// delete directory
if(!dir_empty_delete(mdir2)) {
log_debug("E: Failed to delete %s".printf(mdir2));
}
}
}
}
Expand Down
99 changes: 24 additions & 75 deletions src/Core/SnapshotRepo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -883,77 +883,40 @@ public class SnapshotRepo : GLib.Object{
}

private void delete_directory_thread(){
string cmd = "";
string std_out;
string std_err;
int ret_val;
thr_success = TeeJee.FileSystem.dir_delete_recursive(thr_args1);

try{
var f = File.new_for_path(thr_args1);
if(f.query_exists()){
cmd = "rm -rf \"%s\"".printf(thr_args1);

if (LOG_COMMANDS) { log_debug(cmd); }

Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val);

if (ret_val != 0){
log_error(_("Failed to remove") + ": '%s'".printf(thr_args1));
thr_success = false;
thr_running = false;
return;
}
else{
log_msg(_("Removed") + ": '%s'".printf(thr_args1));
thr_success = true;
thr_running = false;
return;
}
}
else{
log_error(_("Directory not found") + ": '%s'".printf(thr_args1));
thr_success = true;
thr_running = false;
}
}
catch(Error e){
log_error (e.message);
thr_success = false;
thr_running = false;
return;
if (thr_success) {
log_msg(_("Removed") + ": '%s'".printf(thr_args1));
} else{
log_error(_("Failed to remove") + ": '%s'".printf(thr_args1));
}

thr_running = false;
}

// symlinks ----------------------------------------

public void create_symlinks(){
string cmd = "";
string std_out;
string std_err;
int ret_val;

cleanup_symlink_dir("boot");
cleanup_symlink_dir("hourly");
cleanup_symlink_dir("daily");
cleanup_symlink_dir("weekly");
cleanup_symlink_dir("monthly");
cleanup_symlink_dir("ondemand");

string path;

foreach(var bak in snapshots){
foreach(string tag in bak.tags){

path = "%s-%s".printf(snapshots_path, tag);
cmd = "ln --symbolic \"../snapshots/%s\" -t \"%s\"".printf(bak.name, path);

if (LOG_COMMANDS) { log_debug(cmd); }

ret_val = exec_sync(cmd, out std_out, out std_err);
if (ret_val != 0){
log_error (std_err);
log_error(_("Failed to create symlinks") + ": snapshots-%s".printf(tag));
return;
foreach(Snapshot bak in snapshots){
foreach(string tag in bak.tags) {
string linkTarget = "%s-%s/%s".printf(snapshots_path, tag, bak.name);
string linkValue = "../snapshots/" + bak.name;
try {
File f = File.new_for_path(linkTarget);
if (!f.make_symbolic_link(linkValue)) {
log_error(_("Failed to create symlinks") + ": %s".printf(linkTarget));
}
} catch(Error e) {
log_debug(e.message);
log_error(_("Failed to create symlinks") + ": %s".printf(linkTarget));
}
}
}
Expand All @@ -962,32 +925,18 @@ public class SnapshotRepo : GLib.Object{
}

public void cleanup_symlink_dir(string tag){
string cmd = "";
string std_out;
string std_err;
int ret_val;

try{
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 + "/");

if (LOG_COMMANDS) { log_debug(cmd); }

Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val);
if (ret_val != 0){
log_error (std_err);
log_error(_("Failed to delete symlinks") + ": 'snapshots-%s'".printf(tag));
return;
}
if(!TeeJee.FileSystem.dir_delete_recursive(path)) {
log_error(_("Failed to delete symlinks") + ": '%s'".printf(path));
}

File f = File.new_for_path(path);
f.make_directory_with_parents();
}
catch (Error e) {
log_error (e.message);
}
log_error (e.message);
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/AppLock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AppLock : GLib.Object {
lock_message = txt.split(";")[1].strip();
long pid = long.parse(process_id);

if (process_is_running(pid)){
if (get_process_exe_name(pid).contains("timeshift")){
log_msg(_("Another instance of this application is running")
+ " (PID=%ld)".printf(pid));
return false;
Expand Down
4 changes: 1 addition & 3 deletions src/Utility/AsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ public abstract class AsyncTask : GLib.Object{
if (status == AppStatus.RUNNING) {
process_set_priority (child_pid, prio);

Pid sub_child_pid;
foreach (long pid in get_process_children (child_pid)) {
sub_child_pid = (Pid) pid;
foreach (Pid sub_child_pid in get_process_children (child_pid)) {
process_set_priority (sub_child_pid, prio);
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/Utility/DeleteFileTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class DeleteFileTask : AsyncTask{
log_error (e.message);
}
}

public void prepare() {
string script_text = build_script();
log_debug(script_text);
Expand Down Expand Up @@ -113,13 +113,10 @@ public class DeleteFileTask : AsyncTask{
cmd += " '%s/'".printf(escape_single_quote(dest_path));
}
else{
cmd += "rm";
cmd += "rm -rf";

if (verbose){
cmd += " -rfv";
}
else{
cmd += " -rf";
cmd += "v";
}

cmd += " '%s'".printf(escape_single_quote(dest_path));
Expand Down
44 changes: 0 additions & 44 deletions src/Utility/LinuxDistro.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,50 +152,6 @@ public class LinuxDistro : GLib.Object{
return info;
}

public static string get_running_desktop_name(){

/* Return the names of the current Desktop environment */

int pid = -1;

pid = get_pid_by_name("cinnamon");
if (pid > 0){
return "Cinnamon";
}

pid = get_pid_by_name("xfdesktop");
if (pid > 0){
return "Xfce";
}

pid = get_pid_by_name("lxsession");
if (pid > 0){
return "LXDE";
}

pid = get_pid_by_name("gnome-shell");
if (pid > 0){
return "Gnome";
}

pid = get_pid_by_name("wingpanel");
if (pid > 0){
return "Elementary";
}

pid = get_pid_by_name("unity-panel-service");
if (pid > 0){
return "Unity";
}

pid = get_pid_by_name("plasma-desktop");
if (pid > 0){
return "KDE";
}

return "Unknown";
}

public string dist_type {

owned get{
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/RsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public class RsyncTask : AsyncTask{
log_debug("log_file = %s".printf(log_file));

prg_count = 0;
prg_count_total = file_line_count(log_file);
prg_count_total = file_line_count(log_file) ?? 0;

try {
string line;
Expand Down
Loading