Skip to content

Commit

Permalink
refactor: update unix build tags and add plan9 (#224)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kruskall authored Aug 29, 2024
1 parent 8c7c5ca commit 8ec6b25
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
48 changes: 48 additions & 0 deletions file/fileinfo_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build plan9

package file

import (
"errors"
"os"

"golang.org/x/sys/plan9"
)

func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) {
info, err := statFunc(name)
if err != nil {
return nil, err
}

return wrap(info)
}

func wrap(info os.FileInfo) (FileInfo, error) {
stat, ok := info.Sys().(*plan9.Dir)
if !ok {
return nil, errors.New("failed to get uid/gid")
}

// on plan9 uid/gid is a string so we can't cast to int
_ = stat.Uid
_ = stat.Gid
return fileInfo{FileInfo: info, uid: nil, gid: nil}, nil
}
2 changes: 1 addition & 1 deletion file/fileinfo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !windows
//go:build unix

package file

Expand Down
33 changes: 33 additions & 0 deletions file/stderr_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build plan9

package file

import (
"os"

"golang.org/x/sys/plan9"
)

// RedirectStandardError causes all standard error output to be directed to the
// given file.
func RedirectStandardError(toFile *os.File) error {
_, err := plan9.Dup(int(toFile.Fd()), 2)
return err
}
2 changes: 1 addition & 1 deletion file/stderr_other.go → file/stderr_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build !windows
//go:build unix

package file

Expand Down

0 comments on commit 8ec6b25

Please sign in to comment.