~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Utility/CronTab.vala

  • Committer: Tony George
  • Date: 2016-10-16 13:42:12 UTC
  • Revision ID: tony.george.kol@gmail.com-20161016134212-ibjsptmgbha7a2mw
Fixed scheduled backups; Initialize display for the scheduled cron task;

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        }
32
32
 
33
33
        public static bool add_job(string entry){
 
34
                
34
35
                // read crontab file
35
36
                string tab = crontab_read_all();
36
37
                var lines = new Gee.ArrayList<string>();
74
75
                }
75
76
        }
76
77
 
77
 
        public static bool remove_job(string entry){
 
78
        public static bool remove_job(string entry, bool use_regex = false){
 
79
                
78
80
                // read crontab file
79
81
                string tab = crontab_read_all();
80
82
                var lines = new Gee.ArrayList<string>();
81
83
                foreach(string line in tab.split("\n")){
82
84
                        lines.add(line);
83
85
                }
 
86
                
 
87
                Regex regex = null;
 
88
 
 
89
                if (use_regex){
 
90
                        try {
 
91
                                regex = new Regex(entry);
 
92
                        }
 
93
                        catch (Error e) {
 
94
                                log_error (e.message);
 
95
                        }
 
96
                }
84
97
 
85
98
                // check if entry exists
86
99
                bool found = false;
89
102
                        if (line != null){
90
103
                                line = line.strip();
91
104
                        }
92
 
                        if (line == entry){
93
 
                                lines.remove(line);
94
 
                                found = true;
 
105
 
 
106
                        if (use_regex && (regex != null)){
 
107
                                
 
108
                                MatchInfo match;
 
109
                                if (regex.match(line, 0, out match)) {
 
110
                                        lines.remove(line);
 
111
                                        found = true;
 
112
                                }
 
113
                        }
 
114
                        else{
 
115
                                if (line == entry){
 
116
                                        lines.remove(line);
 
117
                                        found = true;
 
118
                                }
95
119
                        }
96
120
                }
97
121
                if (!found){