summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--notes.txt4
-rw-r--r--src/main.c45
2 files changed, 44 insertions, 5 deletions
diff --git a/notes.txt b/notes.txt
index fb6f283..66af513 100644
--- a/notes.txt
+++ b/notes.txt
@@ -5,9 +5,9 @@ also encrypt the /root dir as well. Running as a daemon and setting things up in
5a good idea as well 5a good idea as well
6 6
7vxgg was not atomic in its encryption, in that if the encryption was in progress and interrupted for whatever reason, the original 7vxgg was not atomic in its encryption, in that if the encryption was in progress and interrupted for whatever reason, the original
8file would be "irrecoverably" (as in vxgg had no error checking and couldn't tell the difference between an encrypted and 8file would be "irrecoverably" fucked (as in vxgg had no error checking and couldn't tell the difference between an encrypted and
9unencrypted file other than through filename. You could manually unfuck the file yourself if you had the key, but it would be a 9unencrypted file other than through filename. You could manually unfuck the file yourself if you had the key, but it would be a
10long and tedious process) fucked. I can't possibly make the entire operation of reading and writing to a file atomic, but I can 10long and tedious process). I can't possibly make the entire operation of reading and writing to a file atomic, but I can
11make the action of "encrpytion" atomic; or, at least, I can make the encryption seem atomic through a cheat: hard linking. Turns out 11make the action of "encrpytion" atomic; or, at least, I can make the encryption seem atomic through a cheat: hard linking. Turns out
12that you can make a file in /tmp, fill it with a whole bunch of shit, then hardlink it to somewhere else on the drive, and the 12that you can make a file in /tmp, fill it with a whole bunch of shit, then hardlink it to somewhere else on the drive, and the
13file's contents will persist after a reboot. The idea here is to open a file in /tmp, write the encrypted contents to it, and then 13file's contents will persist after a reboot. The idea here is to open a file in /tmp, write the encrypted contents to it, and then
diff --git a/src/main.c b/src/main.c
index bf110c2..4ecf545 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,15 +4,41 @@
4#include <error.h> 4#include <error.h>
5#include <stdio.h> 5#include <stdio.h>
6 6
7#include <fcntl.h> 7#include <sys/types.h>
8#include <sys/stat.h>
9#include <unistd.h>
8#include <dirent.h> 10#include <dirent.h>
11#include <fcntl.h>
12
13#include <regex.h>
14
15#include <string.h>
16
17regex_t* initfilterregex() {
18 static regex_t *reg = NULL;
19
20 if(reg != NULL)
21 return reg;
22
23 reg = xcalloc(1, sizeof(*reg));
24 if(regcomp(reg, "^(.{1,2})$", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
25 return NULL;
26
27 return reg;
28}
9 29
10int testfilter(const struct dirent *node) { 30int testfilter(const struct dirent *node) {
31 regex_t *reg = initfilterregex();
32
33 if(regexec(reg, node->d_name, 0, NULL, 0) != (REG_NOMATCH | REG_NOERROR) && S_ISDIR(DTTOIF(node->d_type)))
34 return 0;
35
11 return 1; 36 return 1;
12} 37}
13 38
14int main() { 39int main() {
15 // Alright, going to start simple. First: scanning for files. I want to do this quickly and in one motion. No reason to do things in O(n2) time if I can do it in O(n) 40 // Alright, going to start simple. First: scanning for files. I want to do this quickly and in one motion
41 // No reason to do things in O(n2) time if I can do it in O(n)
16 42
17 int nnodes = -1; 43 int nnodes = -1;
18 struct dirent **nodes = NULL; 44 struct dirent **nodes = NULL;
@@ -20,9 +46,22 @@ int main() {
20 error(1, errno, "scandir broke"); 46 error(1, errno, "scandir broke");
21 47
22 for(int i = 0; i < nnodes; i++) { 48 for(int i = 0; i < nnodes; i++) {
23 printf("%s\n", nodes[i]->d_name); 49 printf("\"%s\"", nodes[i]->d_name);
50 #if defined _DIRENT_HAVE_D_TYPE
51 int mode = DTTOIF(nodes[i]->d_type);
52 printf(", Type: %s%s%s",
53 S_ISREG(mode) ? "Regular file" : "",\
54 S_ISDIR(mode) ? "Directory" : "",\
55 (!S_ISREG(mode) && !S_ISDIR(mode)) ? "Unknown" : "");
56
57 #endif
24 58
59 printf("\n");
25 } 60 }
26 61
62 // Ok so scandir is annoying and doesn't create a linked list, but rather an array of dirent objects. This means that if I want
63 // to iterate over the list myself and it'll be a pain in the ass to do so. That, or I can implement a linked list, which would
64 // also be a pain in the ass. I'm starting to remember why I finished vxgg the way I did
65
27 return 0; 66 return 0;
28} \ No newline at end of file 67} \ No newline at end of file