Skip to content

Commit ca4f7f3

Browse files
author
Tim Cooper
committed
fix compilation on unsupported operating systems
1 parent 3f63623 commit ca4f7f3

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

api_darwin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build darwin
2+
13
package lfs
24

35
import (
@@ -7,11 +9,8 @@ import (
79
"github.com/yuin/gopher-lua"
810
)
911

10-
func attributesFill(tbl *lua.LTable, stat os.FileInfo) {
11-
sys, ok := stat.Sys().(*syscall.Stat_t)
12-
if !ok {
13-
return
14-
}
12+
func attributesFill(tbl *lua.LTable, stat os.FileInfo) error {
13+
sys := stat.Sys().(*syscall.Stat_t)
1514
tbl.RawSetH(lua.LString("dev"), lua.LNumber(sys.Dev))
1615
tbl.RawSetH(lua.LString("ino"), lua.LNumber(sys.Ino))
1716
{
@@ -46,4 +45,5 @@ func attributesFill(tbl *lua.LTable, stat os.FileInfo) {
4645
tbl.RawSetH(lua.LString("size"), lua.LNumber(sys.Size))
4746
tbl.RawSetH(lua.LString("blocks"), lua.LNumber(sys.Blocks))
4847
tbl.RawSetH(lua.LString("blksize"), lua.LNumber(sys.Blksize))
48+
return nil
4949
}

api_linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package lfs
24

35
import (
@@ -7,11 +9,8 @@ import (
79
"github.com/yuin/gopher-lua"
810
)
911

10-
func attributesFill(tbl *lua.LTable, stat os.FileInfo) {
11-
sys, ok := stat.Sys().(*syscall.Stat_t)
12-
if !ok {
13-
return
14-
}
12+
func attributesFill(tbl *lua.LTable, stat os.FileInfo) error {
13+
sys := stat.Sys().(*syscall.Stat_t)
1514
tbl.RawSetH(lua.LString("dev"), lua.LNumber(sys.Dev))
1615
tbl.RawSetH(lua.LString("ino"), lua.LNumber(sys.Ino))
1716
{
@@ -46,4 +45,5 @@ func attributesFill(tbl *lua.LTable, stat os.FileInfo) {
4645
tbl.RawSetH(lua.LString("size"), lua.LNumber(sys.Size))
4746
tbl.RawSetH(lua.LString("blocks"), lua.LNumber(sys.Blocks))
4847
tbl.RawSetH(lua.LString("blksize"), lua.LNumber(sys.Blksize))
48+
return nil
4949
}

api_other.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// +build !darwin,!linux
2+
3+
package lfs
4+
5+
import (
6+
"errors"
7+
"os"
8+
"runtime"
9+
10+
"github.com/yuin/gopher-lua"
11+
)
12+
13+
func attributesFill(tbl *lua.LTable, stat os.FileInfo) error {
14+
return errors.New("unsupported operating system " + runtime.GOOS)
15+
}

util.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ func attributes(L *lua.LState, statFunc func(string) (os.FileInfo, error)) int {
1616
return 2
1717
}
1818
table := L.NewTable()
19-
attributesFill(table, stat)
19+
if err := attributesFill(table, stat); err != nil {
20+
L.Push(lua.LNil)
21+
L.Push(lua.LString(err.Error()))
22+
return 2
23+
}
2024
if L.GetTop() > 1 {
2125
aname := L.CheckString(2)
2226
L.Push(table.RawGetH(lua.LString(aname)))

0 commit comments

Comments
 (0)