this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

index all files recursively

+106 -56
formats

This is a binary file and will not be displayed.

library

This is a binary file and will not be displayed.

+106 -56
src/library/library.odin
··· 3 3 import formats "../formats" 4 4 import "core:fmt" 5 5 import "core:mem" 6 + import "core:mem/virtual" 7 + import vmem "core:mem/virtual" 6 8 import "core:os" 7 9 import "core:slice" 8 10 import "core:strings" 9 11 import "core:testing" 10 12 13 + SUPPORTED_EXTENSIONS :: []string{"flac"} 11 14 12 - is_flac :: proc(fi: os.File_Info) -> bool { 13 - return strings.ends_with(fi.name, ".flac") 15 + is_supported :: proc(fi: os.File_Info) -> bool { 16 + for suffix in SUPPORTED_EXTENSIONS { 17 + if strings.has_suffix(fi.fullpath, suffix) { 18 + return true 19 + } 20 + } 21 + return false 14 22 } 15 23 16 24 ReadError :: enum { ··· 20 28 Unable_To_Read_Dir, 21 29 } 22 30 23 - read_dir :: proc( 24 - path: string, 25 - allocator: mem.Allocator = context.allocator, 26 - ) -> ( 27 - result: []formats.VorbisComment, 28 - error: ReadError, 29 - ) { 30 - real_path, err := os.get_absolute_path(path, allocator) 31 - defer delete(real_path) 32 - 33 - if err != nil { 34 - return nil, .Unable_To_Resolve_Absolute_Path 35 - } 36 - 37 - dir_entries: []os.File_Info 38 - dir_entries, err = os.read_all_directory_by_path(real_path, allocator) 39 - defer os.file_info_slice_delete(dir_entries, allocator) 40 - 41 - fmt.printfln("Dir entries: %v", dir_entries) 42 - 43 - if err != nil { 44 - return nil, .Unable_To_Read_Dir 45 - } 46 - 47 - dir_slice := dir_entries[:] 48 - only_flac := slice.filter(dir_slice, is_flac) 49 - defer delete(only_flac) 50 - 51 - fmt.printfln("only flac: %v", only_flac) 31 + // read_dir :: proc( 32 + // path: string, 33 + // allocator: mem.Allocator = context.allocator, 34 + // ) -> ( 35 + // result: []formats.VorbisComment, 36 + // error: ReadError, 37 + // ) { 38 + // real_path, err := os.get_absolute_path(path, allocator) 39 + // defer delete(real_path) 40 + // 41 + // if err != nil { 42 + // return nil, .Unable_To_Resolve_Absolute_Path 43 + // } 44 + // 45 + // dir_entries: []os.File_Info 46 + // dir_entries, err = os.read_all_directory_by_path(real_path, allocator) 47 + // defer os.file_info_slice_delete(dir_entries, allocator) 48 + // 49 + // fmt.printfln("Dir entries: %v", dir_entries) 50 + // 51 + // if err != nil { 52 + // return nil, .Unable_To_Read_Dir 53 + // } 54 + // 55 + // dir_slice := dir_entries[:] 56 + // only_flac := slice.filter(dir_slice, is_flac) 57 + // defer delete(only_flac) 58 + // 59 + // fmt.printfln("only flac: %v", only_flac) 60 + // 61 + // length := len(only_flac) 62 + // 63 + // res := make([]formats.VorbisComment, length) 64 + // defer delete(res) 65 + // 66 + // file: ^os.File 67 + // ferr: os.Error 68 + // 69 + // for i in 0 ..< length { 70 + // entry := only_flac[i] 71 + // 72 + // fmt.printfln("entry %v", entry) 73 + // file, ferr = os.open(entry.fullpath, {.Read}) 74 + // if ferr != nil { 75 + // os.close(file) 76 + // continue 77 + // } 78 + // comment, err := formats.flac_read(file) 79 + // if err != nil { 80 + // os.close(file) 81 + // continue 82 + // } 83 + // res[i] = comment 84 + // os.close(file) 85 + // } 86 + // 87 + // fmt.printfln("\nFound: %v", len(res)) 88 + // 89 + // return res, nil 90 + // } 52 91 53 - length := len(only_flac) 92 + walk_dir :: proc(path: string, allocator := context.allocator) -> [dynamic]string { 54 93 55 - res := make([]formats.VorbisComment, length) 56 - defer delete(res) 94 + w := os.walker_create(path) 95 + defer os.walker_destroy(&w) 96 + paths := make([dynamic]string, allocator) 57 97 58 - file: ^os.File 59 - ferr: os.Error 98 + skipped := 0 99 + failed := 0 60 100 61 - for i in 0 ..< length { 62 - entry := only_flac[i] 101 + for info in os.walker_walk(&w) { 63 102 64 - fmt.printfln("entry %v", entry) 65 - file, ferr = os.open(entry.fullpath, {.Read}) 66 - if ferr != nil { 67 - os.close(file) 103 + if path, err := os.walker_error(&w); err != nil { 104 + fmt.eprintfln("failed walking %s: %s", path, err) 105 + failed += 1 68 106 continue 69 107 } 70 - comment, err := formats.flac_read(file) 71 - if err != nil { 72 - os.close(file) 108 + 109 + if !is_supported(info) { 110 + skipped += 1 73 111 continue 74 112 } 75 - res[i] = comment 76 - os.close(file) 113 + 114 + fmt.printfln("Found: %s", info.fullpath) 115 + append(&paths, info.fullpath) 77 116 } 78 117 79 - fmt.printfln("\nFound: %v", len(res)) 118 + fmt.printfln("=== Total ===") 119 + fmt.printfln("Found: %d", len(paths)) 120 + fmt.printfln("Skipped: %d", skipped) 121 + fmt.printfln("Failed: %d", failed) 122 + fmt.printfln("=============") 80 123 81 - return res, nil 124 + return paths 82 125 } 83 126 84 127 @(test) 85 - should_read_dir :: proc(t: ^testing.T) { 128 + should_index_all_file_paths :: proc(t: ^testing.T) { 86 129 dir_path := "../../test-data/" 87 130 88 - result, err := read_dir(dir_path) 131 + arena: vmem.Arena 132 + arena_err := vmem.arena_init_growing(&arena) 133 + defer vmem.arena_destroy(&arena) 89 134 90 - fmt.printfln("Results: %#v; Err: %v", result, err) 135 + testing.expect(t, arena_err == nil, "Failed to initialize arena") 91 136 92 - testing.expect(t, err == nil) 93 137 94 - for x in result { 95 - formats.destroy_vorbis_comment(x) 96 - } 138 + arena_allocator := vmem.arena_allocator(&arena) 139 + 140 + paths_dyn := walk_dir(dir_path, arena_allocator) 141 + defer delete_dynamic_array(paths_dyn) 142 + 143 + paths := paths_dyn[:] 144 + 145 + testing.expect(t, len(paths) > 0, "Didnt find anything") 146 + 97 147 }