Skip to content

Commit

Permalink
Revert "Revert "Add check to see if dep ensure created the vendor d…
Browse files Browse the repository at this point in the history
…irectory""

This reverts commit 2d90201.
  • Loading branch information
JelteF committed Sep 3, 2017
1 parent 8adf7bb commit b401731
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
12 changes: 12 additions & 0 deletions cmd/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"syscall"

"github.com/BurntSushi/toml"
"github.com/GetStream/vg/internal/utils"
"github.com/GetStream/vg/internal/workspace"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -110,6 +111,17 @@ This command requires that dep is installed in $PATH. `,
return errors.WithStack(err)
}

exists, err := utils.VendorExists()
if err != nil {
return err
}

if !exists {
fmt.Fprintln(os.Stderr, "ERROR: The vendor directory was not created by the dep ensure command.")
fmt.Fprintln(os.Stderr, "ERROR: This means the workspace content won't be changed")
os.Exit(1)
}

err = ws.ClearSrc()
if err != nil {
return errors.Wrap(err, "Couldn't clear the src path of the active workspace")
Expand Down
10 changes: 2 additions & 8 deletions cmd/initSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ var initSettingsCmd = &cobra.Command{
return errors.WithStack(err)
}

// Check if it's a new workspace. Only continue if this is the case or
// if force is set.
_, err = os.Stat(ws.Path())
if err != nil {
if !os.IsNotExist(err) {
return errors.WithStack(err)
}
} else if !force {
exists, err := utils.DirExists(ws.Path())
if !exists && !force {
return nil
}

Expand Down
9 changes: 7 additions & 2 deletions cmd/moveVendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"os"

"github.com/GetStream/vg/internal/utils"
"github.com/GetStream/vg/internal/workspace"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -27,9 +28,13 @@ based project in your workspace do this:
if err != nil {
return err
}
_, err = os.Stat("vendor")

exist, err := utils.VendorExists()
if err != nil {
return errors.Wrap(err, "Something is wrong with the vendor directory")
return err
}
if !exist {
return errors.New("No vendor directory is present")
}

err = ws.ClearSrc()
Expand Down
21 changes: 21 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path/filepath"
"runtime"
"strings"

"github.com/pkg/errors"
)

func ReplaceHomeDir(path string) string {
Expand Down Expand Up @@ -52,6 +54,25 @@ func OriginalGopath() string {
return gopath
}

// exists returns whether the given file or directory exists or not
func DirExists(path string) (bool, error) {
info, err := os.Stat(path)
if err == nil {
if info.IsDir() {
return false, errors.Errorf("%q is not a directory", path)
}
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, errors.Wrapf(err, "error occured when checking if directory %q exists", path)
}

func VendorExists() (bool, error) {
return DirExists("vendor")
}

func CurrentGopath() string {
gopath := os.Getenv("GOPATH")
if gopath == "" {
Expand Down

0 comments on commit b401731

Please sign in to comment.