No global for working dir
This commit is contained in:
+2
-12
@@ -5,22 +5,12 @@ import "core:os"
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
working_dir: string
|
get_working_dir :: proc(allocator := context.allocator) -> string {
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
store_working_dir :: proc(allocator := context.allocator) {
|
|
||||||
wd, err := os.get_working_directory(allocator)
|
wd, err := os.get_working_directory(allocator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.eprintln("error: get working directory failed:", err)
|
fmt.eprintln("error: get working directory failed:", err)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
working_dir = wd
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_working_dir :: proc(allocator := context.allocator) {
|
return wd
|
||||||
if working_dir != "" {
|
|
||||||
delete(working_dir, allocator)
|
|
||||||
working_dir = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,18 +17,20 @@ FileEntry :: struct #all_or_none {
|
|||||||
// Returning `[dynamic]DirectoryEntry` and each relpath `string` inside it are owned by the caller.
|
// Returning `[dynamic]DirectoryEntry` and each relpath `string` inside it are owned by the caller.
|
||||||
list_dir_recursive :: proc(
|
list_dir_recursive :: proc(
|
||||||
f: ^os.File,
|
f: ^os.File,
|
||||||
|
working_dir: string,
|
||||||
allocator := context.allocator,
|
allocator := context.allocator,
|
||||||
) -> [dynamic]FileEntry {
|
) -> [dynamic]FileEntry {
|
||||||
path := os.name(f)
|
path := os.name(f)
|
||||||
return list_dir_recursive_by_path_impl(path, allocator)
|
return list_dir_recursive_by_path_impl(path, working_dir, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returning `[dynamic]DirectoryEntry` and each relpath `string` inside it are owned by the caller.
|
// Returning `[dynamic]DirectoryEntry` and each relpath `string` inside it are owned by the caller.
|
||||||
list_dir_recursive_by_path :: proc(
|
list_dir_recursive_by_path :: proc(
|
||||||
path: string,
|
path: string,
|
||||||
|
working_dir: string,
|
||||||
allocator := context.allocator,
|
allocator := context.allocator,
|
||||||
) -> [dynamic]FileEntry {
|
) -> [dynamic]FileEntry {
|
||||||
return list_dir_recursive_by_path_impl(path, allocator)
|
return list_dir_recursive_by_path_impl(path, working_dir, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frees every owning relpath string then the dynamic array itself.
|
// Frees every owning relpath string then the dynamic array itself.
|
||||||
@@ -42,6 +44,7 @@ delete_entries :: proc(entries: ^[dynamic]FileEntry) {
|
|||||||
@(private)
|
@(private)
|
||||||
list_dir_recursive_by_path_impl :: proc(
|
list_dir_recursive_by_path_impl :: proc(
|
||||||
path: string,
|
path: string,
|
||||||
|
working_dir: string,
|
||||||
allocator: runtime.Allocator,
|
allocator: runtime.Allocator,
|
||||||
) -> [dynamic]FileEntry {
|
) -> [dynamic]FileEntry {
|
||||||
if !os.is_dir(path) {
|
if !os.is_dir(path) {
|
||||||
|
|||||||
+4
-4
@@ -8,16 +8,16 @@ import "src:file"
|
|||||||
VERSION :: #config(VERSION, "dev")
|
VERSION :: #config(VERSION, "dev")
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
file.store_working_dir()
|
working_dir := file.get_working_dir()
|
||||||
defer file.remove_working_dir()
|
defer delete(working_dir)
|
||||||
|
|
||||||
opts := cli.parse(file.working_dir)
|
opts := cli.parse(working_dir)
|
||||||
|
|
||||||
// fmt.println("verbose:", opts.verbose)
|
// fmt.println("verbose:", opts.verbose)
|
||||||
// fmt.println("compression:", opts.compression)
|
// fmt.println("compression:", opts.compression)
|
||||||
// fmt.println("size:", opts.size)
|
// fmt.println("size:", opts.size)
|
||||||
|
|
||||||
entries := file.list_dir_recursive(opts.input)
|
entries := file.list_dir_recursive(opts.input, working_dir)
|
||||||
defer file.delete_entries(&entries)
|
defer file.delete_entries(&entries)
|
||||||
|
|
||||||
w := file.writer_init(cast(u64)len(entries))
|
w := file.writer_init(cast(u64)len(entries))
|
||||||
|
|||||||
Reference in New Issue
Block a user