Skip to content
API Documentation
BastionGuard™
DeleteFileTask Class Reference
Inheritance diagram for DeleteFileTask:
AsyncTask

Public Member Functions

 DeleteFileTask ()
override void prepare ()
override void parse_stdout_line (string out_line)
override void parse_stderr_line (string err_line)
bool update_progress_parse_console_output (string line)
Public Member Functions inherited from AsyncTask
signal void stdout_line_read (string line)
signal void stderr_line_read (string line)
signal void task_complete ()
void write_stdin (string line)
virtual void execute ()
bool is_running ()
void stop (AppStatus status_to_update=AppStatus.CANCELLED)
void pause (AppStatus status_to_update=AppStatus.PAUSED)
void resume (AppStatus status_to_update=AppStatus.RUNNING)
void print_app_status ()

Public Attributes

string dest_path = ""
bool verbose = true
bool io_nice = true
bool use_rsync = false
int64 status_line_count = 0
int64 total_size = 0
string status_message = ""
string time_remaining = ""
Public Attributes inherited from AsyncTask
AppStatus status = AppStatus.NOT_STARTED
GLib.Mutex status_line_mutex
int exit_code = 0
GLib.Timer timer
double progress = 0.0
double percent = 0.0
int64 prg_count = 0
int64 prg_count_total = 0

Protected Member Functions

override string build_script ()
Protected Member Functions inherited from AsyncTask
 AsyncTask ()
string build_script ()
virtual bool begin ()
void parse_stdout_line (string out_line)
void parse_stderr_line (string err_line)
virtual void finish_task ()
int read_exit_code ()

Private Member Functions

void init_regular_expressions ()

Private Attributes

string source_path = ""
Gee.HashMap< string, Regex > regex_list

Additional Inherited Members

Protected Attributes inherited from AsyncTask
DataOutputStream dos_log = null
Pid child_pid = 0
string script_file = ""
string working_dir = ""
Properties inherited from AsyncTask
string status_line [get, set]
double elapsed [get]
string stat_time_elapsed [get]
string??? stat_time_remaining [get]

Detailed Description

Definition at line 31 of file DeleteFileTask.vala.

Constructor & Destructor Documentation

◆ DeleteFileTask()

DeleteFileTask.DeleteFileTask ( )
inline

Definition at line 51 of file DeleteFileTask.vala.

51 {
53 }
void init_regular_expressions()

References init_regular_expressions().

Referenced by Main.Main(), and Snapshot.Snapshot().

Member Function Documentation

◆ build_script()

override string DeleteFileTask.build_script ( )
inlineprotected

Definition at line 80 of file DeleteFileTask.vala.

80 {
81 var cmd = "";
82
83 if (io_nice){
84 //cmd += "ionice -c2 -n7 ";
85 }
86
87 if (use_rsync){
88
89 cmd += "rsync -aii";
90
91 if (verbose){
92 cmd += " --verbose";
93 }
94 else{
95 cmd += " --quiet";
96 }
97
98 cmd += " --delete";
99
100 cmd += " --stats --relative";
101
102 source_path = "/tmp/%s_empty".printf(random_string());
104
107
108 cmd += " '%s/'".printf(escape_single_quote(source_path));
109 cmd += " '%s/'".printf(escape_single_quote(dest_path));
110 }
111 else{
112 cmd += "rm -rf";
113
114 if (verbose){
115 cmd += "v";
116 }
117
118 cmd += " '%s'".printf(escape_single_quote(dest_path));
119 }
120
121 return cmd;
122 }
string escape_single_quote(string file_path)
string remove_trailing_slash(string path)
bool dir_create(string dir_path, bool show_message=false)
string random_string(int length=8, string charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")

References dest_path, TeeJee.FileSystem.dir_create(), TeeJee.FileSystem.escape_single_quote(), io_nice, TeeJee.Misc.random_string(), TeeJee.FileSystem.remove_trailing_slash(), source_path, use_rsync, and verbose.

◆ init_regular_expressions()

void DeleteFileTask.init_regular_expressions ( )
inlineprivate

Definition at line 55 of file DeleteFileTask.vala.

55 {
56 if (regex_list != null){
57 return; // already initialized
58 }
59
60 regex_list = new Gee.HashMap<string,Regex>();
61
62 try {
63
64 regex_list["rsync-deleted"] = new Regex(
65 """\*deleting[ \t]+(.*)""");
66
67 }
68 catch (Error e) {
69 log_error (e.message);
70 }
71 }
Gee.HashMap< string, Regex > regex_list
void log_error(string message, bool highlight=false, bool is_warning=false)

References Error, TeeJee.Logging.log_error(), and regex_list.

Referenced by DeleteFileTask().

◆ parse_stderr_line()

override void DeleteFileTask.parse_stderr_line ( string err_line)
inline

Definition at line 130 of file DeleteFileTask.vala.

130 {
132 }
string err_line
bool update_progress_parse_console_output(string line)

References AsyncTask.err_line, and update_progress_parse_console_output().

◆ parse_stdout_line()

override void DeleteFileTask.parse_stdout_line ( string out_line)
inline

◆ prepare()

override void DeleteFileTask.prepare ( )
inlinevirtual

Reimplemented from AsyncTask.

Definition at line 73 of file DeleteFileTask.vala.

73 {
74 base.prepare();
75
77 total_size = 0;
78 }

References status_line_count, and total_size.

◆ update_progress_parse_console_output()

bool DeleteFileTask.update_progress_parse_console_output ( string line)
inline

Definition at line 134 of file DeleteFileTask.vala.

134 {
135 if ((line == null) || (line.length == 0)) {
136 return true;
137 }
138
140
141 if (prg_count_total > 0){
144 }
145
146 MatchInfo match;
147 if (regex_list["rsync-deleted"].match(line, 0, out match)) {
148
149 //log_debug("matched: rsync-deleted:%s".printf(line));
150
151 status_line = match.fetch(1).split(" -> ")[0].strip();
152 }
153 else {
154
155 //log_debug("matched: else:%s".printf(line));
156
157 status_line = line.strip();
158 }
159
160 return true;
161 }
int64 prg_count
int64 prg_count_total
double progress
string status_line

References AsyncTask.prg_count, AsyncTask.prg_count_total, AsyncTask.progress, regex_list, AsyncTask.status_line, and status_line_count.

Referenced by parse_stderr_line(), and parse_stdout_line().

Member Data Documentation

◆ dest_path

string DeleteFileTask.dest_path = ""

Definition at line 34 of file DeleteFileTask.vala.

Referenced by build_script().

◆ io_nice

bool DeleteFileTask.io_nice = true

Definition at line 36 of file DeleteFileTask.vala.

Referenced by build_script().

◆ regex_list

Gee.HashMap<string, Regex> DeleteFileTask.regex_list
private

◆ source_path

string DeleteFileTask.source_path = ""
private

Definition at line 40 of file DeleteFileTask.vala.

Referenced by build_script().

◆ status_line_count

int64 DeleteFileTask.status_line_count = 0

Definition at line 46 of file DeleteFileTask.vala.

Referenced by prepare(), and update_progress_parse_console_output().

◆ status_message

string DeleteFileTask.status_message = ""

Definition at line 48 of file DeleteFileTask.vala.

Referenced by DeleteBox.delete_snapshots().

◆ time_remaining

string DeleteFileTask.time_remaining = ""

Definition at line 49 of file DeleteFileTask.vala.

◆ total_size

int64 DeleteFileTask.total_size = 0

Definition at line 47 of file DeleteFileTask.vala.

Referenced by prepare().

◆ use_rsync

bool DeleteFileTask.use_rsync = false

Definition at line 37 of file DeleteFileTask.vala.

Referenced by build_script().

◆ verbose

bool DeleteFileTask.verbose = true

Definition at line 35 of file DeleteFileTask.vala.

Referenced by build_script().


The documentation for this class was generated from the following file: