~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Core/FsTabEntry.vala

  • Committer: Tony George
  • Date: 2016-09-18 13:58:57 UTC
  • Revision ID: tony.george.kol@gmail.com-20160918135857-qztjh2kw8mxqfmsf
fstab and crypttab files will be updated correctly on target system when system is restored or cloned

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
        public string pass = "0";
20
20
        public string line = "";
21
21
 
 
22
        public string device_uuid {
 
23
                owned get{
 
24
                        if (device.down().has_prefix("uuid=")){
 
25
                                return device.replace("\"","").replace("'","").split("=")[1];
 
26
                        }
 
27
                        else{
 
28
                                return "";
 
29
                        }
 
30
                }
 
31
                set {
 
32
                        device = "UUID=%s".printf(value);
 
33
                }
 
34
        }
 
35
 
22
36
        public static Gee.ArrayList<FsTabEntry> read_file(string file_path){
23
37
                var list = new Gee.ArrayList<FsTabEntry>();
24
38
 
73
87
                return list;
74
88
        }
75
89
 
76
 
        public static string create_file_text(
77
 
                FsTabEntry[] entries, bool keep_comments_and_empty_lines = true){
 
90
        public static string write_file(
 
91
                Gee.ArrayList<FsTabEntry> entries, string file_path,
 
92
                bool keep_comments_and_empty_lines = false){
78
93
                        
79
94
                string text = "";
 
95
 
 
96
                if (!keep_comments_and_empty_lines){
 
97
                        text += "# <file system> <mount point> <type> <options> <dump> <pass>\n\n";
 
98
                }
 
99
                
80
100
                foreach(var entry in entries){
81
101
                        if (entry.is_comment || entry.is_empty_line){
82
102
                                if (keep_comments_and_empty_lines){
89
109
                                        entry.options, entry.dump, entry.pass);
90
110
                        }
91
111
                }
 
112
 
 
113
                // sort the entries based on mount path
 
114
                // this is required to ensure that base paths are mounted before child paths
 
115
 
 
116
                entries.sort((a, b)=>{
 
117
                        return strcmp(a.mount_point, b.mount_point);
 
118
                });
 
119
                
 
120
                if (file_exists(file_path)){
 
121
                        file_delete(file_path);
 
122
                }
 
123
                
 
124
                file_write(file_path, text);
 
125
                
92
126
                return text;
93
127
        }
94
128
 
95
 
        public string get_uuid(){
96
 
                if (device.down().has_prefix("uuid=")){
97
 
                        return device.replace("\"","").replace("'","").split("=")[1];
 
129
        public string subvolume_name(){
 
130
                if (options.contains("subvol=")){
 
131
                        return options.split("subvol=")[1].split(",")[0].strip();
98
132
                }
99
133
                else{
100
134
                        return "";
101
135
                }
102
136
        }
 
137
 
 
138
        public bool is_for_system_directory(){
 
139
 
 
140
                if (mount_point.has_prefix("/mnt")
 
141
                        || mount_point.has_prefix("/mount")
 
142
                        || mount_point.has_prefix("/sdcard")
 
143
                        || mount_point.has_prefix("/cdrom")
 
144
                        || mount_point.has_prefix("/media")
 
145
                        || (mount_point == "none")
 
146
                        || !mount_point.has_prefix("/")
 
147
                        || (!device.has_prefix("/dev/") && !device.down().has_prefix("uuid="))){
 
148
                        
 
149
                        return false;
 
150
                }
 
151
                else{
 
152
                        return true;
 
153
                }
 
154
        }
 
155
 
 
156
        public static FsTabEntry? find_entry_by_mount_point(
 
157
                Gee.ArrayList<FsTabEntry> entries, string mount_path){
 
158
                        
 
159
                foreach(var entry in entries){
 
160
                        if (entry.mount_point == mount_path){
 
161
                                return entry;
 
162
                        }
 
163
                }
 
164
                return null;
 
165
        }
 
166
 
 
167
        public void append_option(string option){
 
168
                
 
169
                if (!options.contains(option)){
 
170
                        options += ",%s".printf(option);
 
171
                }
 
172
                
 
173
                if(options.has_prefix(",")){
 
174
                        options = options[1:options.length];
 
175
                }
 
176
                
 
177
                options = options.strip();
 
178
        }
 
179
 
 
180
        public void remove_option(string option){
 
181
                
 
182
                options = options.replace(option,"").strip();
 
183
                                        
 
184
                if(options.has_prefix(",")){
 
185
                        options = options[1:options.length];
 
186
                }
 
187
 
 
188
                if (options.has_suffix(",")){
 
189
                        options = options[0:options.length - 1];
 
190
                }
 
191
 
 
192
                options = options.strip();
 
193
        }
103
194
}