github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/vfs/file_lock_windows.go (about) 1 // Copyright 2013 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 // +build windows 6 7 package vfs 8 9 import ( 10 "io" 11 "syscall" 12 ) 13 14 // lockCloser hides all of an syscall.Handle's methods, except for Close. 15 type lockCloser struct { 16 fd syscall.Handle 17 } 18 19 func (l lockCloser) Close() error { 20 return syscall.Close(l.fd) 21 } 22 23 func (defaultFS) Lock(name string) (io.Closer, error) { 24 p, err := syscall.UTF16PtrFromString(name) 25 if err != nil { 26 return nil, err 27 } 28 fd, err := syscall.CreateFile(p, 29 syscall.GENERIC_READ|syscall.GENERIC_WRITE, 30 0, nil, syscall.CREATE_ALWAYS, 31 syscall.FILE_ATTRIBUTE_NORMAL, 32 0, 33 ) 34 if err != nil { 35 return nil, err 36 } 37 return lockCloser{fd: fd}, nil 38 }