Initial commit

This commit is contained in:
Robin Bärtschi 2025-06-18 22:04:25 +02:00
commit ff8ed706da
4 changed files with 158 additions and 0 deletions

30
cmd/cmd.odin Normal file
View File

@ -0,0 +1,30 @@
package cmd
import "../deamon"
import "core:os"
import "core:log"
import "core:hash/xxhash"
import "core:encoding/base64"
Options :: struct {
deamon: bool,
}
main :: proc() {
context.logger = log.create_console_logger()
defer log.destroy_console_logger(context.logger)
d, _ := os.read_entire_file_or_err(os.args[1])
defer delete(d)
hash := xxhash.XXH3_128(d)
hash_bytes := transmute([size_of(hash)]u8)hash
data, _ := base64.encode(hash_bytes[:])
base64.ENC_TABLE
log.infof("%q", data)
//
// deamon.handle_inotify()
}

43
deamon/deamon.odin Normal file
View File

@ -0,0 +1,43 @@
package deamon
import "core:log"
import "core:sys/posix"
import "core:sys/linux"
NAME_MAX :: posix.NAME_MAX
handle_inotify :: proc() {
fd, err := linux.inotify_init()
if err != nil {
log.fatalf("Could not initalize inotify: %v", err)
}
watch, watch_err := linux.inotify_add_watch(fd, "./cmd/", linux.IN_ALL_EVENTS | {.ONLYDIR})
if watch_err != nil {
log.fatalf("Could not add watch to directory 'cmd': %v", watch_err)
}
log.infof("Initalized with wd %v for %v", watch, fd)
for {
buffer: [size_of(linux.Inotify_Event)+NAME_MAX+1]u8
size, err := linux.read(fd, buffer[:])
if err == .EINVAL {
log.debug(err)
continue
} else if err != .NONE {
log.errorf("Could not read inotify fd: %v", err)
continue
}
i := 0
for size >= size_of(linux.Inotify_Event) {
event := (cast(^linux.Inotify_Event)&buffer[i])^
name := event.len > 0 ? cstring(raw_data(buffer[size_of(linux.Inotify_Event)+i:int(event.len)+i])) : ""
log.infof("%q: %v", name, event)
size -= int(size_of(linux.Inotify_Event)+event.len)
i += int(size_of(linux.Inotify_Event)+event.len)
}
}
}

20
store/ini.odin Normal file
View File

@ -0,0 +1,20 @@
package store
// Ini Reflection code
import "core:mem"
import "core:reflect"
import "core:encoding/ini"
import "core:encoding/json"
Ini_Unmarshal_Error :: union {
mem.Allocator_Error,
}
ini_unmarshal :: proc(data: string, v: ^$T, allocator := context.allocator) -> Ini_Unmarshal_Error {
m := ini.load_map_from_string(data, allocator) or_return
defer ini.delete_map(m)
fields := reflect.struct_fields_zipped(T)
}

65
store/store.odin Normal file
View File

@ -0,0 +1,65 @@
// This package contains all data that is saved on disc. So everything in the .ezs folder
package store
// .ezs directory structure
// .ezs/
// backups/ -- Contains backups of old files
// [a-zA-Z0-9\-_]{2}/ -- Custom Base64 encoded XXH3_128 prefix for the backups
// [HASH] -- The backed up file, the hash is used to identify it. What about collisions? We mention that in the data file next to it
// [HASH].ini -- The data file for file [HASH], contains things like filename and also collision data
// superpositions/ -- Contains data about superpositions TODO: Define
// config.ini -- Contains general config data
import "core:mem"
import "core:time"
import "core:encoding/base64"
Config_Backups :: struct {
enabled: bool `ini:"default=true"`,
interval: time.Duration `ini:"default=10m"`,
}
Config :: struct {
backups: Config_Backups,
}
// Custom base64 tables
ENC_TABLE := [64]byte {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '-', '_',
}
DEC_TABLE := [128]int {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 62, -1, -1,
52, 53, 54, 55, 56, 57, 58, 59,
60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1, 63,
-1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, -1, -1, -1, -1, -1,
}
base64_encode :: proc(data: []byte, allocator := context.allocator) -> (encoded: string, err: mem.Allocator_Error) #optional_allocator_error {
return base64.encode(data, ENC_TABLE, allocator)
}
base64_decode :: proc(data: string, allocator := context.allocator) -> (decoded: []byte, err: mem.Allocator_Error) #optional_allocator_error {
return base64.decode(data, DEC_TABLE, allocator)
}