forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer_windows_test.go
33 lines (30 loc) · 979 Bytes
/
analyzer_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package dep
import (
"io"
"os"
"syscall"
)
// makeUnreadable opens the file at path in exclusive mode. A file opened in
// exclusive mode cannot be opened again until the exclusive mode file handle
// is closed.
func makeUnreadable(path string) (io.Closer, error) {
if len(path) == 0 {
return nil, syscall.ERROR_FILE_NOT_FOUND
}
pathp, err := syscall.UTF16PtrFromString(path)
if err != nil {
return nil, err
}
access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE)
sharemode := uint32(0) // no sharing == exclusive mode
sa := (*syscall.SecurityAttributes)(nil)
createmode := uint32(syscall.OPEN_EXISTING)
h, err := syscall.CreateFile(pathp, access, sharemode, sa, createmode, syscall.FILE_ATTRIBUTE_NORMAL, 0)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(h), path), nil
}