diff --git a/src/AppConsole.vala b/src/AppConsole.vala index a4554b77..1975a40b 100644 --- a/src/AppConsole.vala +++ b/src/AppConsole.vala @@ -76,7 +76,7 @@ public class AppConsole : GLib.Object { } LOG_ENABLE = false; - init_tmp(AppShortName); + init_tmp(); LOG_ENABLE = true; check_if_admin(); diff --git a/src/AppGtk.vala b/src/AppGtk.vala index c5414d44..a6f5a0f7 100644 --- a/src/AppGtk.vala +++ b/src/AppGtk.vala @@ -70,7 +70,7 @@ public class AppGtk : GLib.Object { GTK_INITIALIZED = true; - init_tmp(AppShortName); + init_tmp(); check_if_admin(); diff --git a/src/Utility/TeeJee.Process.vala b/src/Utility/TeeJee.Process.vala index 1f55311b..94e32bf3 100644 --- a/src/Utility/TeeJee.Process.vala +++ b/src/Utility/TeeJee.Process.vala @@ -34,23 +34,34 @@ namespace TeeJee.ProcessHelper{ // execute process --------------------------------- - public static void init_tmp(string subdir_name){ - string std_out, std_err; + public static void init_tmp(){ - TEMP_DIR = Environment.get_tmp_dir() + "/" + random_string(); - dir_create(TEMP_DIR); - chmod(TEMP_DIR, "0750"); - - 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/" + random_string(); + // a list of folders where temp files could be stored + string[] tempPlaces = { + Environment.get_tmp_dir(), // system temp dir + "/var/tmp", // another system temp dir, if the first one failed, this one is likely to fail too + Environment.get_home_dir() + "/.temp", // user temp dir + "/dev/shm", // shared memory + }; + + foreach (string tempPlace in tempPlaces) { + string std_out, std_err; + + TEMP_DIR = tempPlace + "/timeshift-" + random_string(); dir_create(TEMP_DIR); chmod(TEMP_DIR, "0750"); + exec_script_sync("echo 'ok'",out std_out,out std_err, true); + + if ((std_out == null) || (std_out.strip() != "ok")){ + // this dir does not work for some reason - probably no disk space + dir_delete(TEMP_DIR); + } else { + // script worked - we have found a tempdir to use + return; + } } - //log_debug("TEMP_DIR=" + TEMP_DIR); + stderr.printf("No usable temp directory was found!\n"); } public int exec_sync (string cmd, out string? std_out = null, out string? std_err = null){ @@ -81,7 +92,12 @@ namespace TeeJee.ProcessHelper{ * std_out, std_err can be null. Output will be written to terminal if null. * */ - string sh_file = save_bash_script_temp(script, null, true, supress_errors); + string? sh_file = save_bash_script_temp(script, null, true, supress_errors); + if (sh_file == null) { + // saving the script failed + return -1; + } + string sh_file_admin = ""; if (run_as_admin){ @@ -204,7 +220,6 @@ namespace TeeJee.ProcessHelper{ script.append ("\n"); script.append ("%s\n".printf(commands)); script.append ("\n\nexitCode=$?\n"); - script.append ("echo ${exitCode} > ${exitCode}\n"); script.append ("echo ${exitCode} > status\n"); if ((sh_path == null) || (sh_path.length == 0)){