Skip to content

Commit 8ec6b25

Browse files
authored
refactor: update unix build tags and add plan9 (#224)
* refactor: update unix build tags and add plan9 resolve obscure compile errors when trying to compile on different goos. Use unix build tags and add plan9. We can't implement uid/gid logic without breaks as plan9 uses strings while the api requires int. Use plan9.Dup to redirect stderr. * refactor: use syscall type
1 parent 8c7c5ca commit 8ec6b25

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

file/fileinfo_plan9.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//go:build plan9
19+
20+
package file
21+
22+
import (
23+
"errors"
24+
"os"
25+
26+
"golang.org/x/sys/plan9"
27+
)
28+
29+
func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) {
30+
info, err := statFunc(name)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
return wrap(info)
36+
}
37+
38+
func wrap(info os.FileInfo) (FileInfo, error) {
39+
stat, ok := info.Sys().(*plan9.Dir)
40+
if !ok {
41+
return nil, errors.New("failed to get uid/gid")
42+
}
43+
44+
// on plan9 uid/gid is a string so we can't cast to int
45+
_ = stat.Uid
46+
_ = stat.Gid
47+
return fileInfo{FileInfo: info, uid: nil, gid: nil}, nil
48+
}

file/fileinfo_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//go:build !windows
18+
//go:build unix
1919

2020
package file
2121

file/stderr_plan9.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//go:build plan9
19+
20+
package file
21+
22+
import (
23+
"os"
24+
25+
"golang.org/x/sys/plan9"
26+
)
27+
28+
// RedirectStandardError causes all standard error output to be directed to the
29+
// given file.
30+
func RedirectStandardError(toFile *os.File) error {
31+
_, err := plan9.Dup(int(toFile.Fd()), 2)
32+
return err
33+
}

file/stderr_other.go renamed to file/stderr_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//go:build !windows
18+
//go:build unix
1919

2020
package file
2121

0 commit comments

Comments
 (0)