Skip to content

Commit

Permalink
Start of Bindfs support
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Jul 30, 2017
1 parent b1cfdbc commit aa08c97
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
53 changes: 51 additions & 2 deletions internal/workspace/localInstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path"
"path/filepath"

Expand Down Expand Up @@ -51,7 +52,24 @@ func (ws *Workspace) InstallLocalPackage(pkg string, localPath string) error {
return err
}

err = ws.installLocalPackageWithSymlink(pkg, localPath, target)
hasBindfs := true

_, err = exec.LookPath("bindfs")
if err != nil {
execErr, ok := err.(*exec.Error)
if !ok || execErr.Err != exec.ErrNotFound {
return err
}

hasBindfs = false
}

if hasBindfs {
err = ws.installLocalPackageWithBindfs(pkg, localPath, target)
} else {
err = ws.installLocalPackageWithSymlink(pkg, localPath, target)
}

if err != nil {
return err
}
Expand All @@ -61,8 +79,39 @@ func (ws *Workspace) InstallLocalPackage(pkg string, localPath string) error {

}

func (ws *Workspace) installLocalPackageWithBindfs(pkg, src, target string) error {
_, _ = fmt.Fprintf(os.Stderr, "Installing local sources at %q in workspace as %q using bindfs\n", src, pkg)

settings, err := ws.Settings()
if err != nil {
return err
}

settings.LocalInstalls[pkg].Bindfs = true

err = ws.SaveSettings(settings)
if err != nil {
return err
}

err = os.MkdirAll(target, 0755)
if err != nil {
return errors.WithStack(err)
}

cmd := exec.Command("bindfs")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stderr
err = cmd.Run()
if err != nil {
return errors.WithStack(err)
}

return nil
}

func (ws *Workspace) installLocalPackageWithSymlink(pkg, src, target string) error {
_, _ = fmt.Fprintf(os.Stderr, "Installing local sources at %q in workspace as %q\n", src, pkg)
_, _ = fmt.Fprintf(os.Stderr, "Installing local sources at %q in workspace as %q using symbolic links\n", src, pkg)

err := os.MkdirAll(filepath.Dir(target), 0755)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/workspace/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type localInstall struct {
Path string `toml:"path"`
Persistent bool `toml:"persistent"`
Successful bool `toml:"successful"`
Bindfs bool `toml:"bindfs"`
}

func NewSettings() *Settings {
Expand Down

0 comments on commit aa08c97

Please sign in to comment.