Use regular expression matching for searching crontab entries

This commit is contained in:
Tony George 2014-08-17 17:13:42 +05:30
parent 52d996b66d
commit b43d25703a
3 changed files with 22 additions and 9 deletions

View File

@ -2186,7 +2186,7 @@ public class Main : GLib.Object{
}
else{
//remove current entry
crontab_remove_job(search_string);
crontab_remove_job(current_entry);
}
}
@ -2197,13 +2197,13 @@ public class Main : GLib.Object{
//boot job ----------------------------------
search_string = "&& timeshift";
search_string = """@reboot sleep [0-9]*m && timeshift --backup""";
new_entry = get_crontab_entry_boot();
new_entry_exists = false;
//read
current_entry = crontab_read_entry(search_string);
current_entry = crontab_read_entry(search_string, true);
if (current_entry.length > 0) {
//check
@ -2213,7 +2213,7 @@ public class Main : GLib.Object{
}
else{
//remove current entry
crontab_remove_job(search_string);
crontab_remove_job(current_entry);
}
}

View File

@ -2271,13 +2271,19 @@ namespace TeeJee.System{
}
}
public string crontab_read_entry(string search_string){
public string crontab_read_entry(string search_string, bool use_regex_matching = false){
string cmd = "";
string std_out;
string std_err;
int ret_val;
try{
Regex rex = null;
MatchInfo match;
if (use_regex_matching){
rex = new Regex(search_string);
}
cmd = "crontab -l";
Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val);
if (ret_val != 0){
@ -2285,8 +2291,15 @@ namespace TeeJee.System{
}
else{
foreach(string line in std_out.split("\n")){
if (line.contains(search_string)){
return line.strip();
if (use_regex_matching && (rex != null)){
if (rex.match (line, 0, out match)){
return line.strip();
}
}
else {
if (line.contains(search_string)){
return line.strip();
}
}
}
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: timeshift 1.2\n"
"Report-Msgid-Bugs-To: teejee2008@gmail.com\n"
"POT-Creation-Date: 2014-08-17 16:47+0530\n"
"POT-Creation-Date: 2014-08-17 17:10+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -225,7 +225,7 @@ msgstr ""
msgid "Cron job removed"
msgstr ""
#: Utility.vala:2261 Utility.vala:2284
#: Utility.vala:2261 Utility.vala:2290
msgid "Crontab is empty"
msgstr ""