github.com/sdboyer/gps@v0.16.3/strip_vendor_windows.go (about)

     1  package gps
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  )
     7  
     8  func stripVendor(path string, info os.FileInfo, err error) error {
     9  	if info.Name() == "vendor" {
    10  		if _, err := os.Lstat(path); err == nil {
    11  			symlink := (info.Mode() & os.ModeSymlink) != 0
    12  			dir := info.IsDir()
    13  
    14  			switch {
    15  			case symlink && dir:
    16  				// This could be a windows junction directory. Support for these in the
    17  				// standard library is spotty, and we could easily delete an important
    18  				// folder if we called os.Remove or os.RemoveAll. Just skip these.
    19  				//
    20  				// TODO: If we could distinguish between junctions and Windows symlinks,
    21  				// we might be able to safely delete symlinks, even though junctions are
    22  				// dangerous.
    23  				return filepath.SkipDir
    24  
    25  			case symlink:
    26  				realInfo, err := os.Stat(path)
    27  				if err != nil {
    28  					return err
    29  				}
    30  				if realInfo.IsDir() {
    31  					return os.Remove(path)
    32  				}
    33  
    34  			case dir:
    35  				return removeAll(path)
    36  			}
    37  		}
    38  	}
    39  
    40  	return nil
    41  }