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

Commit

Permalink
Updated project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
teejee2008 committed Aug 13, 2016
1 parent ce4fed9 commit 9538300
Show file tree
Hide file tree
Showing 31 changed files with 13,283 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/Common/FsTabEntry.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.Devices;
using TeeJee.JsonHelper;
using TeeJee.ProcessHelper;
using TeeJee.GtkHelper;
using TeeJee.System;
using TeeJee.Misc;

public class FsTabEntry : GLib.Object{
public bool is_comment = false;
public bool is_empty_line = false;
public string device = "";
public string mount_point = "";
public string type = "";
public string options = "defaults";
public string dump = "0";
public string pass = "0";
public string line = "";

public static Gee.ArrayList<FsTabEntry> read_fstab_file(string fstab_file_path){
Gee.ArrayList<FsTabEntry> list = new Gee.ArrayList<FsTabEntry>();

if (!file_exists(fstab_file_path)){ return list; }

string text = file_read(fstab_file_path);
string[] lines = text.split("\n");
foreach(string line in lines){
FsTabEntry entry = new FsTabEntry();
list.add(entry);

entry.is_comment = line.strip().has_prefix("#");
entry.is_empty_line = (line.strip().length == 0);

if (entry.is_comment){
entry.line = line;
}
else if (entry.is_empty_line){
entry.line = "";
}
else{
entry.line = line;

string[] parts = line.replace("\t"," ").split(" ");
int part_num = -1;
foreach(string part in parts){
if (part.strip().length == 0) { continue; }
switch (++part_num){
case 0:
entry.device = part.strip();
break;
case 1:
entry.mount_point = part.strip();
break;
case 2:
entry.type = part.strip();
break;
case 3:
entry.options = part.strip();
break;
case 4:
entry.dump = part.strip();
break;
case 5:
entry.pass = part.strip();
break;
}
}
}
}

return list;
}

public static string create_fstab_file(FsTabEntry[] fstab_entries, bool keep_comments_and_empty_lines = true){
string text = "";
foreach(FsTabEntry entry in fstab_entries){
if (entry.is_comment || entry.is_empty_line){
if (keep_comments_and_empty_lines){
text += "%s\n".printf(entry.line);
}
}
else {
text += "%s\t%s\t%s\t%s\t%s\t%s\n".printf(entry.device, entry.mount_point, entry.type, entry.options, entry.dump, entry.pass);
}
}
return text;
}
}
18 changes: 18 additions & 0 deletions src/Common/MountEntry.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.Devices;
using TeeJee.JsonHelper;
using TeeJee.ProcessHelper;
using TeeJee.GtkHelper;
using TeeJee.System;
using TeeJee.Misc;

public class MountEntry : GLib.Object{
public Device device = null;
public string mount_point = "";

public MountEntry(Device device, string mount_point){
this.device = device;
this.mount_point = mount_point;
}
}
Loading

0 comments on commit 9538300

Please sign in to comment.