Skip to content

add "timeshift" to the tempdir names #395

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

Open
wants to merge 5 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
2 changes: 1 addition & 1 deletion src/AppConsole.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class AppConsole : GLib.Object {
}

LOG_ENABLE = false;
init_tmp(AppShortName);
init_tmp();
LOG_ENABLE = true;

check_if_admin();
Expand Down
2 changes: 1 addition & 1 deletion src/AppGtk.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class AppGtk : GLib.Object {

GTK_INITIALIZED = true;

init_tmp(AppShortName);
init_tmp();

check_if_admin();

Expand Down
43 changes: 29 additions & 14 deletions src/Utility/TeeJee.Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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)){
Expand Down
Loading