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

Commit 37619b1

Browse files
author
Mya Pitzeruse
authored
gh-14: added stop command (#22)
* gh-14: added stop command * gh-14: fixed up imports
1 parent 1432340 commit 37619b1

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

cmd/gitfs/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
57
"github.com/mjpitz/gitfs/cmd"
68
"github.com/spf13/cobra"
7-
"os"
89
)
910

1011
func main() {
@@ -18,6 +19,7 @@ func main() {
1819
"Specify the configuration path")
1920

2021
rootCmd.AddCommand(cmd.StartCommand)
22+
rootCmd.AddCommand(cmd.StopCommand)
2123

2224
if err := rootCmd.Execute(); err != nil {
2325
fmt.Println(err)

cmd/global.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package cmd
22

33
import (
4-
"github.com/sirupsen/logrus"
54
"os"
5+
6+
"github.com/sirupsen/logrus"
67
)
78

89
var (

cmd/start.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package cmd
22

33
import (
4+
"os"
5+
"os/user"
6+
"strconv"
7+
"strings"
8+
49
"bazil.org/fuse"
510
"bazil.org/fuse/fs"
611
"github.com/mjpitz/gitfs/pkg/clone"
@@ -10,10 +15,6 @@ import (
1015
"github.com/mjpitz/gitfs/pkg/tree"
1116
"github.com/sirupsen/logrus"
1217
"github.com/spf13/cobra"
13-
"os"
14-
"os/user"
15-
"strconv"
16-
"strings"
1718
)
1819

1920
var StartCommand = &cobra.Command{

cmd/stop.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"syscall"
6+
7+
"github.com/mjpitz/gitfs/pkg/config"
8+
"github.com/sirupsen/logrus"
9+
"github.com/spf13/cobra"
10+
"golang.org/x/sys/unix"
11+
)
12+
13+
var StopCommand = &cobra.Command{
14+
Use: "stop",
15+
Short: "Stops the file system server.",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
props := ConfigPath
18+
if len(props) == 0 {
19+
fail("missing config file")
20+
}
21+
22+
cfg, err := config.Load(os.ExpandEnv(props))
23+
if err != nil {
24+
fail("failed to parse configuration: %v", err)
25+
}
26+
27+
mountpoint := os.ExpandEnv(cfg.Mount)
28+
29+
logrus.Infof("Unmounting %s", mountpoint)
30+
31+
_ = syscall.Unmount(mountpoint, unix.MNT_FORCE)
32+
// ignore the error since it's likely not mounted
33+
},
34+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
golang.org/x/net v0.0.0-20181220203305-927f97764cc3
1919
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890
2020
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
21-
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb // indirect
21+
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb
2222
google.golang.org/appengine v1.4.0 // indirect
2323
gopkg.in/src-d/go-billy.v4 v4.3.0
2424
gopkg.in/src-d/go-git-fixtures.v3 v3.3.0 // indirect

pkg/clone/cloner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package clone
33
import (
44
"crypto/sha256"
55
"encoding/base32"
6+
"os"
7+
"regexp"
8+
69
"github.com/mjpitz/gitfs/pkg/config"
710
"github.com/mjpitz/gitfs/pkg/sync"
811
"github.com/pkg/errors"
@@ -13,8 +16,6 @@ import (
1316
"gopkg.in/src-d/go-git.v4"
1417
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1518
"gopkg.in/src-d/go-git.v4/storage/filesystem"
16-
"os"
17-
"regexp"
1819
)
1920

2021
func NewCloner(cfg *config.CloneConfiguration) *Cloner {

0 commit comments

Comments
 (0)