Skip to content

Commit

Permalink
#164 write human delta to /tmp/wd.delta on all changes, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Apr 30, 2024
1 parent 5c5c3bd commit ff1166b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TST_E = $(patsubst tst/%.c,%,$(wildcard tst/tst-*.c))
TST_T = $(patsubst tst%,test%,$(TST_E))

all: way-displays
../duke.sh

$(SRC_O): $(INC_H) $(PRO_H) config.mk GNUmakefile
$(PRO_O): $(PRO_H) config.mk GNUmakefile
Expand Down
2 changes: 1 addition & 1 deletion inc/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

bool mkdir_p(char *path, mode_t mode);

bool file_write(const char *path, const char *contents);
bool file_write(const char *path, const char *contents, const char *mode);

#endif // FS_H

4 changes: 2 additions & 2 deletions src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ void cfg_file_write(void) {
goto end;
}

if (cfg->file_path && (written = file_write(cfg->file_path, yaml))) {
if (cfg->file_path && (written = file_write(cfg->file_path, yaml, "w"))) {
cfg->updated = true;
goto end;
}
Expand All @@ -841,7 +841,7 @@ void cfg_file_write(void) {
set_paths(cfg, i->val, i->val);

// attempt to write
if (mkdir_p(cfg->dir_path, 0755) && (written = file_write(i->val, yaml))) {
if (mkdir_p(cfg->dir_path, 0755) && (written = file_write(i->val, yaml, "w"))) {

// watch the new
fd_wd_cfg_dir_create();
Expand Down
4 changes: 2 additions & 2 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ bool mkdir_p(char *path, mode_t mode) {
return rc;
}

bool file_write(const char *path, const char *contents) {
bool file_write(const char *path, const char *contents, const char *mode) {
if (!path || !contents) {
return false;
}

FILE *f = fopen(path, "w");
FILE *f = fopen(path, mode);

if (!f) {
log_error_errno("\nUnable to write to %s", path);
Expand Down
19 changes: 19 additions & 0 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "cfg.h"
#include "displ.h"
#include "fs.h"
#include "global.h"
#include "head.h"
#include "info.h"
Expand Down Expand Up @@ -298,8 +299,26 @@ void apply(void) {

} else {

// TODO provide a means to capture into a provided list or buffer or file, as other captures are going on
log_capture_clear();
log_capture_start();

print_heads(INFO, DELTA, heads);

log_capture_stop();

// TODO unique file name, pass it to the callback
if (file_write("/tmp/wd.delta", "", "w")) {
for (struct SList *i = log_cap_lines; i; i = i->nex) {
struct LogCapLine *cap_line = (struct LogCapLine*)i->val;
if (strlen(cap_line->line) > 0) {
file_write("/tmp/wd.delta", cap_line->line, "a");
}
}
}

log_capture_clear();

// all changes except mode
for (i = heads_changing; i; i = i->nex) {
struct Head *head = (struct Head*)i->val;
Expand Down

0 comments on commit ff1166b

Please sign in to comment.