github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/util_nix.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  //go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
     5  // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
     6  
     7  package libkb
     8  
     9  import (
    10  	"errors"
    11  	"os"
    12  )
    13  
    14  func canExec(s string) error {
    15  	fi, err := os.Stat(s)
    16  	if err != nil {
    17  		return err
    18  	}
    19  	mode := fi.Mode()
    20  
    21  	//
    22  	// Only consider non-directories that have at least one +x
    23  	//  bit set.
    24  	//
    25  	// TODO: Recheck this on Windows!
    26  	//   See here for lookpath: http://golang.org/src/pkg/os/exec/lp_windows.go
    27  	//
    28  	// Similar to check from exec.LookPath below
    29  	//   See here: http://golang.org/src/pkg/os/exec/lp_unix.go
    30  	//
    31  
    32  	if mode.IsDir() {
    33  		return DirExecError{Path: s}
    34  	}
    35  
    36  	if mode&0111 == 0 {
    37  		return FileExecError{Path: s}
    38  	}
    39  
    40  	return nil
    41  }
    42  
    43  func PosixLineEndings(arg string) string {
    44  	return arg
    45  }
    46  
    47  func AppDataDir() (string, error) {
    48  	return "", errors.New("unsupported: AppDataDir")
    49  }
    50  
    51  func LocalDataDir() (string, error) {
    52  	return "", errors.New("unsupported: LocalDataDir")
    53  }
    54  
    55  // SafeWriteToFile is a pass-through to safeWriteToFileOnce on non-Windows.
    56  func SafeWriteToFile(g SafeWriteLogger, t SafeWriter, mode os.FileMode) error {
    57  	return safeWriteToFileOnce(g, t, mode)
    58  }
    59  
    60  func renameFile(_ *GlobalContext, src string, dest string) error {
    61  	return os.Rename(src, dest)
    62  }
    63  
    64  func ChangeMountIcon(oldMount string, newMount string) error {
    65  	return nil
    66  }