-
Notifications
You must be signed in to change notification settings - Fork 150
all: re-implement Windows support #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !windows | ||
|
||
package main | ||
|
||
import ( | ||
platform "golang.org/x/sys/unix" | ||
) | ||
|
||
const PLATFORM_SIGTERM = platform.SIGTERM |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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. | ||
|
||
package main | ||
|
||
import ( | ||
platform "golang.org/x/sys/windows" | ||
) | ||
|
||
const PLATFORM_SIGTERM = platform.SIGTERM | ||
|
||
// Memory map metrics are provided in metrics_nonlinux.go |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//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. | ||
|
||
// Other platforms do 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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !windows | ||
|
||
package index | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func init() { | ||
umask = os.FileMode(unix.Umask(0)) | ||
unix.Umask(int(umask)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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. | ||
|
||
package index | ||
|
||
// No OS-specific imports needed | ||
|
||
func init() { | ||
// no setting of file permissions on Windows | ||
umask = 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build linux || darwin | ||
//go:build !windows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small comment, this file could be named |
||
|
||
package index | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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. | ||
|
||
package index | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are really supporting Windows, we should use mmap here instead of direct reads. This provides the best experience, and I think it's an easier mental model for debugging/ support, to consistently use file mapping. Maybe we could re-introduce |
||
_, 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 >= math.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() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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. | ||
|
||
package index | ||
|
||
func init() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part doesn't look right to me -- isn't this already handled in By the way, I'm generally confused on why we are storing the system |
||
// no setting of file permissions on Windows | ||
umask = 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny comment: these comments are unrelated to the change and not super useful (and also use "I" in an inaccurate way :))