github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/sysutil/sysutil_windows.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  // +build windows
    12  
    13  package sysutil
    14  
    15  import (
    16  	"fmt"
    17  	"os"
    18  	"os/user"
    19  	"syscall"
    20  
    21  	"github.com/cockroachdb/errors"
    22  )
    23  
    24  // ProcessIdentity returns a string describing the user and group that this
    25  // process is running as.
    26  func ProcessIdentity() string {
    27  	u, err := user.Current()
    28  	if err != nil {
    29  		return "<unknown>"
    30  	}
    31  	return fmt.Sprintf("uid %s, gid %s", u.Uid, u.Gid)
    32  }
    33  
    34  // StatFS returns an FSInfo describing the named filesystem. It is only
    35  // supported on Unix-like platforms.
    36  func StatFS(path string) (*FSInfo, error) {
    37  	return nil, errors.New("unsupported on Windows")
    38  }
    39  
    40  // StatAndLinkCount wraps os.Stat, returning its result and a zero link count.
    41  func StatAndLinkCount(path string) (os.FileInfo, int64, error) {
    42  	stat, err := os.Stat(path)
    43  	return stat, 0, err
    44  }
    45  
    46  // IsCrossDeviceLinkErrno checks whether the given error object (as
    47  // extracted from an *os.LinkError) is a cross-device link/rename
    48  // error.
    49  func IsCrossDeviceLinkErrno(errno error) bool {
    50  	// 0x11 is Win32 Error Code ERROR_NOT_SAME_DEVICE
    51  	// See: https://msdn.microsoft.com/en-us/library/cc231199.aspx
    52  	return errno == syscall.Errno(0x11)
    53  }