github.com/tonyghita/glide@v0.13.2-0.20171214012703-3e13fd16ed5b/path/strip.go (about)

     1  package path
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/Masterminds/glide/godep/strip"
     8  	"github.com/Masterminds/glide/msg"
     9  )
    10  
    11  func getWalkFunction(searchPath string, removeAll func(p string) error) func(path string,
    12  	info os.FileInfo, err error) error {
    13  	return func(path string, info os.FileInfo, err error) error {
    14  		if err != nil {
    15  			return err
    16  		}
    17  
    18  		// Skip the base vendor directory
    19  		if path == searchPath {
    20  			return nil
    21  		}
    22  
    23  		if info.Name() == "vendor" && info.IsDir() {
    24  			msg.Info("Removing: %s", path)
    25  			err = removeAll(path)
    26  			if nil != err {
    27  				return err
    28  			}
    29  			return filepath.SkipDir
    30  		}
    31  		return nil
    32  	}
    33  }
    34  
    35  // StripVendor removes nested vendor and Godeps/_workspace/ directories.
    36  func StripVendor() error {
    37  	searchPath, _ := Vendor()
    38  	if _, err := os.Stat(searchPath); err != nil {
    39  		if os.IsNotExist(err) {
    40  			msg.Debug("Vendor directory does not exist.")
    41  		}
    42  
    43  		return err
    44  	}
    45  
    46  	err := filepath.Walk(searchPath, getWalkFunction(searchPath, CustomRemoveAll))
    47  
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	return strip.GodepWorkspace(searchPath)
    53  }