-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters