mirror of https://github.com/Hilbis/Hilbish
fix(fs)!: handle mkdir error, change error return for cd
breaking change: cd now returns a message instead of a code to indicate the error. any error in mkdir is now handledpull/78/head
parent
539a39f83a
commit
20acfad2c2
|
@ -40,16 +40,8 @@ func fcd(L *lua.LState) int {
|
||||||
|
|
||||||
err := os.Chdir(strings.TrimSpace(path))
|
err := os.Chdir(strings.TrimSpace(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch e := err.(*os.PathError).Err.Error(); e {
|
e := err.(*os.PathError).Err.Error()
|
||||||
case "no such file or directory":
|
luaErr(L, e)
|
||||||
luaErr(L, 1)
|
|
||||||
case "not a directory":
|
|
||||||
luaErr(L, 2)
|
|
||||||
default:
|
|
||||||
fmt.Printf("Found unhandled error case: %s\n", e)
|
|
||||||
fmt.Printf("Report this at https://github.com/Rosettea/Hilbish/issues with the title being: \"fs: unhandled error case %s\", and show what caused it.\n", e)
|
|
||||||
luaErr(L, 213)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -61,12 +53,15 @@ func fmkdir(L *lua.LState) int {
|
||||||
dirname := L.CheckString(1)
|
dirname := L.CheckString(1)
|
||||||
recursive := L.ToBool(2)
|
recursive := L.ToBool(2)
|
||||||
path := strings.TrimSpace(dirname)
|
path := strings.TrimSpace(dirname)
|
||||||
|
var err error
|
||||||
|
|
||||||
// TODO: handle error here
|
|
||||||
if recursive {
|
if recursive {
|
||||||
os.MkdirAll(path, 0744)
|
err = os.MkdirAll(path, 0744)
|
||||||
} else {
|
} else {
|
||||||
os.Mkdir(path, 0744)
|
err = os.Mkdir(path, 0744)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
luaErr(L, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue