Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

Commit

Permalink
gh-14: added stop command (#22)
Browse files Browse the repository at this point in the history
* gh-14: added stop command

* gh-14: fixed up imports
  • Loading branch information
Mya Pitzeruse authored Jan 1, 2019
1 parent 1432340 commit 37619b1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cmd/gitfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
"os"

"github.com/mjpitz/gitfs/cmd"
"github.com/spf13/cobra"
"os"
)

func main() {
Expand All @@ -18,6 +19,7 @@ func main() {
"Specify the configuration path")

rootCmd.AddCommand(cmd.StartCommand)
rootCmd.AddCommand(cmd.StopCommand)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/global.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"github.com/sirupsen/logrus"
"os"

"github.com/sirupsen/logrus"
)

var (
Expand Down
9 changes: 5 additions & 4 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package cmd

import (
"os"
"os/user"
"strconv"
"strings"

"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/mjpitz/gitfs/pkg/clone"
Expand All @@ -10,10 +15,6 @@ import (
"github.com/mjpitz/gitfs/pkg/tree"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
"os/user"
"strconv"
"strings"
)

var StartCommand = &cobra.Command{
Expand Down
34 changes: 34 additions & 0 deletions cmd/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"os"
"syscall"

"github.com/mjpitz/gitfs/pkg/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
)

var StopCommand = &cobra.Command{
Use: "stop",
Short: "Stops the file system server.",
Run: func(cmd *cobra.Command, args []string) {
props := ConfigPath
if len(props) == 0 {
fail("missing config file")
}

cfg, err := config.Load(os.ExpandEnv(props))
if err != nil {
fail("failed to parse configuration: %v", err)
}

mountpoint := os.ExpandEnv(cfg.Mount)

logrus.Infof("Unmounting %s", mountpoint)

_ = syscall.Unmount(mountpoint, unix.MNT_FORCE)
// ignore the error since it's likely not mounted
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
golang.org/x/net v0.0.0-20181220203305-927f97764cc3
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.0
gopkg.in/src-d/go-git-fixtures.v3 v3.3.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions pkg/clone/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package clone
import (
"crypto/sha256"
"encoding/base32"
"os"
"regexp"

"github.com/mjpitz/gitfs/pkg/config"
"github.com/mjpitz/gitfs/pkg/sync"
"github.com/pkg/errors"
Expand All @@ -13,8 +16,6 @@ import (
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"os"
"regexp"
)

func NewCloner(cfg *config.CloneConfiguration) *Cloner {
Expand Down

0 comments on commit 37619b1

Please sign in to comment.