diff --git a/file/fileinfo_plan9.go b/file/fileinfo_plan9.go new file mode 100644 index 00000000..59aa7591 --- /dev/null +++ b/file/fileinfo_plan9.go @@ -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 +} diff --git a/file/fileinfo_unix.go b/file/fileinfo_unix.go index b1c98b8d..355bed91 100644 --- a/file/fileinfo_unix.go +++ b/file/fileinfo_unix.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -//go:build !windows +//go:build unix package file diff --git a/file/stderr_plan9.go b/file/stderr_plan9.go new file mode 100644 index 00000000..f3a97ccf --- /dev/null +++ b/file/stderr_plan9.go @@ -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 +} diff --git a/file/stderr_other.go b/file/stderr_unix.go similarity index 98% rename from file/stderr_other.go rename to file/stderr_unix.go index 5af8611c..463b31ac 100644 --- a/file/stderr_other.go +++ b/file/stderr_unix.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -//go:build !windows +//go:build unix package file