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

Commit

Permalink
Change TEMP_DIR permissions and path; Cleanup on exit;
Browse files Browse the repository at this point in the history
  • Loading branch information
teejee2008 committed Mar 5, 2020
1 parent 4447b0a commit 335b3d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4244,6 +4244,8 @@ public class Main : GLib.Object{
clean_logs();

app_lock.remove();

dir_delete(TEMP_DIR);

exit(exit_code);

Expand Down
7 changes: 7 additions & 0 deletions src/Utility/TeeJee.FileSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,11 @@ namespace TeeJee.FileSystem{

try{
var dir = File.parse_name (dir_path);

if (dir.query_exists () == false) {

bool ok = dir.make_directory_with_parents (null);

if (show_message){
if (ok){
log_msg(_("Created directory") + ": %s".printf(dir_path));
Expand All @@ -355,6 +358,7 @@ namespace TeeJee.FileSystem{
}
}
}

return true;
}
catch (Error e) {
Expand All @@ -373,9 +377,12 @@ namespace TeeJee.FileSystem{
}

string cmd = "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);

if (show_message){
if (status == 0){
log_msg(_("Deleted directory") + ": %s".printf(dir_path));
Expand Down
13 changes: 8 additions & 5 deletions src/Utility/TeeJee.Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ namespace TeeJee.ProcessHelper{
public static void init_tmp(string subdir_name){
string std_out, std_err;

TEMP_DIR = Environment.get_tmp_dir() + "/" + subdir_name + "/" + random_string();
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/" + subdir_name + "/" + random_string();
exec_sync("rm -rf '%s'".printf(TEMP_DIR), null, null);

if ((std_out == null) || (std_out.strip() != "ok")){

TEMP_DIR = Environment.get_home_dir() + "/.temp/" + random_string();
dir_create(TEMP_DIR);
chmod(TEMP_DIR, "0750");
}

//log_debug("TEMP_DIR=" + TEMP_DIR);
Expand Down

0 comments on commit 335b3d5

Please sign in to comment.