...

Source file src/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go

Documentation: go.etcd.io/etcd/client/pkg/v3/fileutil

     1  // Copyright 2016 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build windows
    16  // +build windows
    17  
    18  package fileutil
    19  
    20  import (
    21  	"os"
    22  	"syscall"
    23  )
    24  
    25  const (
    26  	// PrivateDirMode grants owner to make/remove files inside the directory.
    27  	PrivateDirMode = 0777
    28  )
    29  
    30  // OpenDir opens a directory in windows with write access for syncing.
    31  func OpenDir(path string) (*os.File, error) {
    32  	fd, err := openDir(path)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  	return os.NewFile(uintptr(fd), path), nil
    37  }
    38  
    39  func openDir(path string) (fd syscall.Handle, err error) {
    40  	if len(path) == 0 {
    41  		return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND
    42  	}
    43  	pathp, err := syscall.UTF16PtrFromString(path)
    44  	if err != nil {
    45  		return syscall.InvalidHandle, err
    46  	}
    47  	access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE)
    48  	sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE)
    49  	createmode := uint32(syscall.OPEN_EXISTING)
    50  	fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS)
    51  	return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0)
    52  }
    53  

View as plain text