From 5b368d8456dc9902befdbbf51b99ca7a63217c56 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 4 Feb 2025 16:23:32 -0800 Subject: [PATCH] Fully revert windows support --- cmd/zoekt-sourcegraph-indexserver/meta.go | 6 ++ .../meta_unix.go | 14 ----- .../meta_windows.go | 6 -- cmd/zoekt-webserver/main.go | 28 ++------- cmd/zoekt-webserver/main_unix.go | 9 --- cmd/zoekt-webserver/main_unsupported.go | 18 ------ cmd/zoekt-webserver/main_windows.go | 7 --- .../{main_linux.go => metrics.go} | 0 index/builder.go | 12 +++- index/builder_unix.go | 29 --------- index/{indexfile_unix.go => indexfile.go} | 0 index/indexfile_other.go | 62 ------------------- index/tombstones_unix.go | 14 ----- index/tombstones_windows.go | 6 -- 14 files changed, 20 insertions(+), 191 deletions(-) delete mode 100644 cmd/zoekt-sourcegraph-indexserver/meta_unix.go delete mode 100644 cmd/zoekt-sourcegraph-indexserver/meta_windows.go delete mode 100644 cmd/zoekt-webserver/main_unix.go delete mode 100644 cmd/zoekt-webserver/main_unsupported.go delete mode 100644 cmd/zoekt-webserver/main_windows.go rename cmd/zoekt-webserver/{main_linux.go => metrics.go} (100%) delete mode 100644 index/builder_unix.go rename index/{indexfile_unix.go => indexfile.go} (100%) delete mode 100644 index/indexfile_other.go delete mode 100644 index/tombstones_unix.go delete mode 100644 index/tombstones_windows.go diff --git a/cmd/zoekt-sourcegraph-indexserver/meta.go b/cmd/zoekt-sourcegraph-indexserver/meta.go index 9be31bb3a..94f448c11 100644 --- a/cmd/zoekt-sourcegraph-indexserver/meta.go +++ b/cmd/zoekt-sourcegraph-indexserver/meta.go @@ -8,6 +8,7 @@ import ( "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/index" + "golang.org/x/sys/unix" ) // mergeMeta updates the .meta files for the shards on disk for o. @@ -110,3 +111,8 @@ func jsonMarshalTmpFile(v interface{}, p string) (_ string, err error) { // respect process umask. build does this. var umask os.FileMode + +func init() { + umask = os.FileMode(unix.Umask(0)) + unix.Umask(int(umask)) +} diff --git a/cmd/zoekt-sourcegraph-indexserver/meta_unix.go b/cmd/zoekt-sourcegraph-indexserver/meta_unix.go deleted file mode 100644 index 29fe8e507..000000000 --- a/cmd/zoekt-sourcegraph-indexserver/meta_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !windows - -package main - -import ( - "os" - - "golang.org/x/sys/unix" -) - -func init() { - umask = os.FileMode(unix.Umask(0)) - unix.Umask(int(umask)) -} diff --git a/cmd/zoekt-sourcegraph-indexserver/meta_windows.go b/cmd/zoekt-sourcegraph-indexserver/meta_windows.go deleted file mode 100644 index 3411af911..000000000 --- a/cmd/zoekt-sourcegraph-indexserver/meta_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package main - -func init() { - // no setting of file permissions on Windows - umask = 0 -} diff --git a/cmd/zoekt-webserver/main.go b/cmd/zoekt-webserver/main.go index 4f4e2b2ae..eb282fdfc 100644 --- a/cmd/zoekt-webserver/main.go +++ b/cmd/zoekt-webserver/main.go @@ -32,7 +32,6 @@ import ( "os" "os/signal" "path/filepath" - "runtime" "strconv" "strings" "sync" @@ -45,6 +44,7 @@ import ( "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" + "golang.org/x/sys/unix" "google.golang.org/grpc" "github.com/opentracing/opentracing-go" @@ -374,8 +374,8 @@ func addProxyHandler(mux *http.ServeMux, socket string) { // times you will read the channel (used as buffer for signal.Notify). func shutdownSignalChan(maxReads int) <-chan os.Signal { c := make(chan os.Signal, maxReads) - signal.Notify(c, os.Interrupt) // terminal C-c and goreman - signal.Notify(c, PLATFORM_SIGTERM) // Kubernetes + signal.Notify(c, os.Interrupt) // terminal C-c and goreman + signal.Notify(c, unix.SIGTERM) // Kubernetes return c } @@ -484,28 +484,13 @@ Possible remediations: } } -func diskUsage(path string) (*disk.UsageStat, error) { - duPath := path - if runtime.GOOS == "windows" { - duPath = filepath.VolumeName(duPath) - } - usage, err := disk.Usage(duPath) - if err != nil { - return nil, fmt.Errorf("diskUsage: %w", err) - } - return usage, err -} - func mustRegisterDiskMonitor(path string) { prometheus.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{ Name: "src_disk_space_available_bytes", Help: "Amount of free space disk space.", ConstLabels: prometheus.Labels{"path": path}, }, func() float64 { - // I know there is no error handling here, and I don't like it - // but there was no error handling in the previous version - // that used Statfs, either, so I'm assuming there's no need for it - usage, _ := diskUsage(path) + usage, _ := disk.Usage(path) return float64(usage.Free) })) @@ -514,10 +499,7 @@ func mustRegisterDiskMonitor(path string) { Help: "Amount of total disk space.", ConstLabels: prometheus.Labels{"path": path}, }, func() float64 { - // I know there is no error handling here, and I don't like it - // but there was no error handling in the previous version - // that used Statfs, either, so I'm assuming there's no need for it - usage, _ := diskUsage(path) + usage, _ := disk.Usage(path) return float64(usage.Total) })) } diff --git a/cmd/zoekt-webserver/main_unix.go b/cmd/zoekt-webserver/main_unix.go deleted file mode 100644 index cdcc52a0d..000000000 --- a/cmd/zoekt-webserver/main_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -//go:build !windows - -package main - -import ( - platform "golang.org/x/sys/unix" -) - -const PLATFORM_SIGTERM = platform.SIGTERM diff --git a/cmd/zoekt-webserver/main_unsupported.go b/cmd/zoekt-webserver/main_unsupported.go deleted file mode 100644 index c2e7002ef..000000000 --- a/cmd/zoekt-webserver/main_unsupported.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build !linux - -package main - -import ( - sglog "github.com/sourcegraph/log" -) - -func mustRegisterMemoryMapMetrics(logger sglog.Logger) { - // The memory map metrics are collected via /proc, which - // is only available on linux-based operating systems. - - // as far as I can tell, Windows does not have the same - // virtual memory statistics as Linux. - // For example, Windows does not have the concept of - // a count of memory maps, and a max number of memory maps - return -} diff --git a/cmd/zoekt-webserver/main_windows.go b/cmd/zoekt-webserver/main_windows.go deleted file mode 100644 index 0e2a1ed23..000000000 --- a/cmd/zoekt-webserver/main_windows.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import ( - platform "golang.org/x/sys/windows" -) - -const PLATFORM_SIGTERM = platform.SIGTERM diff --git a/cmd/zoekt-webserver/main_linux.go b/cmd/zoekt-webserver/metrics.go similarity index 100% rename from cmd/zoekt-webserver/main_linux.go rename to cmd/zoekt-webserver/metrics.go diff --git a/index/builder.go b/index/builder.go index 34d02f31b..91f7f9b34 100644 --- a/index/builder.go +++ b/index/builder.go @@ -40,6 +40,7 @@ import ( "github.com/dustin/go-humanize" "github.com/go-enry/go-enry/v2" "github.com/rs/xid" + "golang.org/x/sys/unix" "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/internal/ctags" @@ -1090,9 +1091,6 @@ func (e *deltaIndexOptionsMismatchError) Error() string { return fmt.Sprintf("one or more index options for shard %q do not match Builder's index options. These index option updates are incompatible with delta build. New index options: %+v", e.shardName, e.newOptions) } -// umask holds the Umask of the current process -var umask os.FileMode - // Document holds a document (file) to index. type Document struct { Name string @@ -1113,3 +1111,11 @@ type Document struct { type DocumentSection struct { Start, End uint32 } + +// umask holds the Umask of the current process +var umask os.FileMode + +func init() { + umask = os.FileMode(unix.Umask(0)) + unix.Umask(int(umask)) +} diff --git a/index/builder_unix.go b/index/builder_unix.go deleted file mode 100644 index 07768c0dd..000000000 --- a/index/builder_unix.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2018 Google Inc. All rights reserved. -// -// Licensed 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 !windows && !wasm -// +build !windows,!wasm - -package index - -import ( - "os" - - "golang.org/x/sys/unix" -) - -func init() { - umask = os.FileMode(unix.Umask(0)) - unix.Umask(int(umask)) -} diff --git a/index/indexfile_unix.go b/index/indexfile.go similarity index 100% rename from index/indexfile_unix.go rename to index/indexfile.go diff --git a/index/indexfile_other.go b/index/indexfile_other.go deleted file mode 100644 index 2a5b427b9..000000000 --- a/index/indexfile_other.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2016 Google Inc. All rights reserved. -// -// Licensed 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 !linux && !darwin -// +build !linux,!darwin - -package index - -import ( - "fmt" - "os" -) - -// NewIndexFile returns a new index file. The index file takes -// ownership of the passed in file, and may close it. -func NewIndexFile(f *os.File) (IndexFile, error) { - return &indexFileFromOS{f}, nil -} - -type indexFileFromOS struct { - f *os.File -} - -func (f *indexFileFromOS) Read(off, sz uint32) ([]byte, error) { - r := make([]byte, sz) - _, err := f.f.ReadAt(r, int64(off)) - return r, err -} - -func (f indexFileFromOS) Size() (uint32, error) { - fi, err := f.f.Stat() - if err != nil { - return 0, err - } - - sz := fi.Size() - - if sz >= maxUInt32 { - return 0, fmt.Errorf("overflow") - } - - return uint32(sz), nil -} - -func (f indexFileFromOS) Close() { - f.f.Close() -} - -func (f indexFileFromOS) Name() string { - return f.f.Name() -} diff --git a/index/tombstones_unix.go b/index/tombstones_unix.go deleted file mode 100644 index b4c6e9bad..000000000 --- a/index/tombstones_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !windows && !wasm - -package index - -import ( - "os" - - "golang.org/x/sys/unix" -) - -func init() { - umask = os.FileMode(unix.Umask(0)) - unix.Umask(int(umask)) -} diff --git a/index/tombstones_windows.go b/index/tombstones_windows.go deleted file mode 100644 index 8ac62aa07..000000000 --- a/index/tombstones_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package index - -func init() { - // no setting of file permissions on Windows - umask = 0 -}