github.com/dmitris/glide@v0.0.0-20170130172825-a68f1bf824dc/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  // StripVendor removes nested vendor and Godeps/_workspace/ directories.
    12  func StripVendor() error {
    13  	searchPath, _ := Vendor()
    14  	if _, err := os.Stat(searchPath); err != nil {
    15  		if os.IsNotExist(err) {
    16  			msg.Debug("Vendor directory does not exist.")
    17  		}
    18  
    19  		return err
    20  	}
    21  
    22  	err := filepath.Walk(searchPath, func(path string, info os.FileInfo, err error) error {
    23  		// Skip the base vendor directory
    24  		if path == searchPath {
    25  			return nil
    26  		}
    27  
    28  		name := info.Name()
    29  		if name == "vendor" {
    30  			if _, err := os.Stat(path); err == nil {
    31  				if info.IsDir() {
    32  					msg.Info("Removing: %s", path)
    33  					return os.RemoveAll(path)
    34  				}
    35  
    36  				msg.Debug("%s is not a directory. Skipping removal", path)
    37  				return nil
    38  			}
    39  		}
    40  		return nil
    41  	})
    42  	if err != nil {
    43  		return err
    44  	}
    45  
    46  	return strip.GodepWorkspace(searchPath)
    47  }