Skip to content

Commit a46c438

Browse files
committed
test: use github actions instead of travis
also fix some compatibility issues
1 parent ebf0e75 commit a46c438

File tree

7 files changed

+98
-32
lines changed

7 files changed

+98
-32
lines changed

.travis/client_conf.json renamed to .github/client_conf.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"session": {
1313
"type": "ntlm",
14-
"user": "travis",
15-
"passwd": "travis"
14+
"user": "smbuser",
15+
"passwd": "Smbpasswd12345"
1616
},
1717
"tree_conn": {
1818
"share1": "tmp",
File renamed without changes.

.github/workflows/go.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
on: [push, pull_request]
2+
jobs:
3+
test_linux:
4+
strategy:
5+
matrix:
6+
go: [1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17]
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/setup-go@v3
10+
with:
11+
go-version: ${{ matrix.go }}
12+
- uses: actions/checkout@v3
13+
- run: |
14+
sudo apt install -y samba
15+
sudo groupadd smbgroup
16+
sudo useradd smbuser -G smbgroup
17+
(echo Smbpasswd12345; echo Smbpasswd12345) | sudo smbpasswd -a -s smbuser
18+
sudo cp ./.github/smb.conf /etc/samba/smb.conf
19+
sudo smbd
20+
- uses: actions/cache@v2
21+
with:
22+
path: |
23+
~/go/pkg/mod
24+
~/.cache/go-build
25+
~/Library/Caches/go-build
26+
~\AppData\Local\go-build
27+
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
28+
restore-keys: ${{ runner.os }}-go-${{ matrix.go }}-
29+
- run: |
30+
cp ./.github/client_conf.json ./
31+
go test -v -race ./...
32+
test_windows:
33+
strategy:
34+
matrix:
35+
go: [1.15, 1.16, 1.17]
36+
runs-on: windows-latest
37+
steps:
38+
- uses: actions/setup-go@v3
39+
with:
40+
go-version: ${{ matrix.go }}
41+
- uses: actions/checkout@v3
42+
- run: |
43+
mkdir C:\tmp
44+
net user smbuser Smbpasswd12345 /add
45+
net share tmp="C:\tmp" /GRANT:smbuser,full
46+
net share tmp2="C:\tmp" /GRANT:smbuser,read
47+
- uses: actions/cache@v2
48+
with:
49+
path: |
50+
~/go/pkg/mod
51+
~/.cache/go-build
52+
~/Library/Caches/go-build
53+
~\AppData\Local\go-build
54+
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
55+
restore-keys: ${{ runner.os }}-go-${{ matrix.go }}-
56+
- run: |
57+
cp ./.github/client_conf.json ./
58+
go test -v -race ./...

.travis.yml

-24
This file was deleted.

client.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"math"
87
"math/rand"
98
"net"
109
"os"
@@ -797,6 +796,11 @@ func (fs *Share) ReadDir(dirname string) ([]os.FileInfo, error) {
797796
return fis, nil
798797
}
799798

799+
const (
800+
intSize = 32 << (^uint(0) >> 63) // 32 or 64
801+
maxInt = 1<<(intSize-1) - 1
802+
)
803+
800804
func (fs *Share) ReadFile(filename string) ([]byte, error) {
801805
f, err := fs.Open(filename)
802806
if err != nil {
@@ -808,7 +812,7 @@ func (fs *Share) ReadFile(filename string) ([]byte, error) {
808812

809813
var size int
810814

811-
if size64 <= math.MaxInt {
815+
if size64 <= maxInt {
812816
size = int(size64)
813817

814818
// If a file claims a small size, read at least 512 bytes.
@@ -819,7 +823,7 @@ func (fs *Share) ReadFile(filename string) ([]byte, error) {
819823
size = 512
820824
}
821825
} else {
822-
size = math.MaxInt
826+
size = maxInt
823827
}
824828

825829
data := make([]byte, 0, size)

client_fs.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build go1.6
1+
// +build go1.16
22

33
package smb2
44

@@ -48,6 +48,34 @@ func (fs *wfs) ReadFile(name string) ([]byte, error) {
4848
return fs.share.ReadFile(fs.path(name))
4949
}
5050

51+
// dirInfo is a DirEntry based on a FileInfo.
52+
type dirInfo struct {
53+
fileInfo fs.FileInfo
54+
}
55+
56+
func (di dirInfo) IsDir() bool {
57+
return di.fileInfo.IsDir()
58+
}
59+
60+
func (di dirInfo) Type() fs.FileMode {
61+
return di.fileInfo.Mode().Type()
62+
}
63+
64+
func (di dirInfo) Info() (fs.FileInfo, error) {
65+
return di.fileInfo, nil
66+
}
67+
68+
func (di dirInfo) Name() string {
69+
return di.fileInfo.Name()
70+
}
71+
72+
func fileInfoToDirEntry(info fs.FileInfo) fs.DirEntry {
73+
if info == nil {
74+
return nil
75+
}
76+
return dirInfo{fileInfo: info}
77+
}
78+
5179
type wfile struct {
5280
*File
5381
}
@@ -59,7 +87,7 @@ func (f *wfile) ReadDir(n int) (dirents []fs.DirEntry, err error) {
5987
}
6088
dirents = make([]fs.DirEntry, len(infos))
6189
for i, info := range infos {
62-
dirents[i] = fs.FileInfoToDirEntry(info)
90+
dirents[i] = fileInfoToDirEntry(info)
6391
}
6492
return dirents, nil
6593
}

smb2_fs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build go1.6
1+
// +build go1.16
22

33
package smb2_test
44

0 commit comments

Comments
 (0)