Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only commit successful directory changes #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/file_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,32 @@ Errno fb_change_dir(File_Browser *fb)

const char *dir_name = fb->files.items[fb->cursor];

fb->dir_path.count -= 1;
String_Builder new_path = { 0 };
da_append_many(&new_path, fb->dir_path.items, fb->dir_path.count);

// TODO: fb->dir_path grows indefinitely if we hit the root
sb_append_cstr(&fb->dir_path, "/");
sb_append_cstr(&fb->dir_path, dir_name);

String_Builder result = {0};
normpath(sb_to_sv(fb->dir_path), &result);
da_move(&fb->dir_path, result);
sb_append_null(&fb->dir_path);
new_path.count -= 1;

printf("Changed dir to %s\n", fb->dir_path.items);
// TODO: fb->dir_path grows indefinitely if we hit the root
sb_append_cstr(&new_path, "/");
sb_append_cstr(&new_path, dir_name);

fb->files.count = 0;
fb->cursor = 0;
Errno err = read_entire_dir(fb->dir_path.items, &fb->files);
String_Builder result = { 0 };
normpath(sb_to_sv(new_path), &result);
da_move(&new_path, result);
sb_append_null(&new_path);

Files new_files = { 0 };
Errno err = read_entire_dir(new_path.items, &new_files);
if (err != 0) {
return err;
}

da_move(&fb->files, new_files);
da_move(&fb->dir_path, new_path);
fb->cursor = 0;

printf("Changed dir to %s\n", fb->dir_path.items);

qsort(fb->files.items, fb->files.count, sizeof(*fb->files.items), file_cmp);

return 0;
Expand Down