github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/ioutil/is_exist_windows.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package ioutil
     6  
     7  import (
     8  	"os"
     9  	"syscall"
    10  
    11  	"github.com/pkg/errors"
    12  )
    13  
    14  const error_DIR_NOT_EMPTY = syscall.Errno(145)
    15  
    16  // IsExist wraps os.IsExist to work around
    17  // https://github.com/golang/go/issues/17164 .
    18  func IsExist(err error) bool {
    19  	err = errors.Cause(err)
    20  	if os.IsExist(err) {
    21  		return true
    22  	}
    23  	switch pe := err.(type) {
    24  	case nil:
    25  		return false
    26  	case *os.PathError:
    27  		err = pe.Err
    28  	case *os.LinkError:
    29  		err = pe.Err
    30  	case *os.SyscallError:
    31  		err = pe.Err
    32  	}
    33  	return err == error_DIR_NOT_EMPTY
    34  }