diff options
| author | gingerBill <bill@gingerbill.org> | 2020-09-28 12:39:34 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-09-28 12:39:34 +0100 |
| commit | d343e47a868a674cbb15508cef53bbcf8a6bd04c (patch) | |
| tree | 3af561e65b1fda937e512187d03f116d637c29bd /core/path/filepath | |
| parent | 1d21740afb7785535d6e1cf01aa92a039ec3cdf0 (diff) | |
Add `user_data` parameter to `filepath.walk` and `filepath.Walk_Proc`
Diffstat (limited to 'core/path/filepath')
| -rw-r--r-- | core/path/filepath/walk.odin | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/core/path/filepath/walk.odin b/core/path/filepath/walk.odin index 4143bc557..dfa37bf2f 100644 --- a/core/path/filepath/walk.odin +++ b/core/path/filepath/walk.odin @@ -14,7 +14,7 @@ import "core:sort" // The sole exception is if 'skip_dir' is returned as true: // when 'skip_dir' is invoked on a directory. 'walk' skips directory contents // when 'skip_dir' is invoked on a non-directory. 'walk' skips the remaining files in the containing directory -Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip_dir: bool); +Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Errno, skip_dir: bool); // walk walks the file tree rooted at 'root', calling 'walk_proc' for each file or directory in the tree, including 'root' // All errors that happen visiting files and directories are filtered by walk_proc @@ -22,28 +22,28 @@ Walk_Proc :: #type proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, // NOTE: Walking large directories can be inefficient due to the lexical sort // NOTE: walk does not follow symbolic links // NOTE: os.File_Info uses the 'context.temp_allocator' to allocate, and will delete when it is done -walk :: proc(root: string, walk_proc: Walk_Proc) -> os.Errno { +walk :: proc(root: string, walk_proc: Walk_Proc, user_data: rawptr) -> os.Errno { info, err := os.lstat(root, context.temp_allocator); defer os.file_info_delete(info, context.temp_allocator); skip_dir: bool; if err != 0 { - err, skip_dir = walk_proc(info, err); + err, skip_dir = walk_proc(info, err, user_data); } else { - err, skip_dir = _walk(info, walk_proc); + err, skip_dir = _walk(info, walk_proc, user_data); } return 0 if skip_dir else err; } @(private) -_walk :: proc(info: os.File_Info, walk_proc: Walk_Proc) -> (err: os.Errno, skip_dir: bool) { +_walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (err: os.Errno, skip_dir: bool) { if !info.is_dir { if info.fullpath == "" && info.name == "" { // ignore empty things return; } - return walk_proc(info, 0); + return walk_proc(info, 0, user_data); } fis: []os.File_Info; @@ -51,14 +51,14 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc) -> (err: os.Errno, skip_ fis, err = read_dir(info.fullpath, context.temp_allocator); defer os.file_info_slice_delete(fis, context.temp_allocator); - err1, skip_dir = walk_proc(info, err); + err1, skip_dir = walk_proc(info, err, user_data); if err != 0 || err1 != 0 || skip_dir { err = err1; return; } for fi in fis { - err, skip_dir = _walk(fi, walk_proc); + err, skip_dir = _walk(fi, walk_proc, user_data); if err != 0 || skip_dir { if !fi.is_dir || !skip_dir { return; |