-
Notifications
You must be signed in to change notification settings - Fork 0
/
unservecmd.go
61 lines (53 loc) · 1.48 KB
/
unservecmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package commands
import (
"fmt"
"github.com/codegangsta/cli"
pb "github.com/cpssd/paranoid/proto/fileserver"
"golang.org/x/net/context"
"google.golang.org/grpc"
"os"
"os/user"
"path/filepath"
"time"
)
//Removes files from Paranoid File Server
func Unserve(c *cli.Context) {
args := c.Args()
if len(args) < 2 {
cli.ShowCommandHelp(c, "unserve")
os.Exit(1)
}
usr, err := user.Current()
if err != nil {
fmt.Println("Unable to get information on current user:", err)
Log.Fatal("Could not get user information:", err)
}
ip, port, uuid, pool := getFsMeta(usr, args[0])
address := ip + ":" + port
var opts []grpc.DialOption
opts = append(opts, grpc.WithTimeout(2*time.Second))
opts = append(opts, grpc.WithInsecure())
connection, err := grpc.Dial(address, opts...)
if err != nil {
fmt.Println("Failed to Connect to Discovery Share Server")
Log.Fatal("Unable to Connect to Discovery Share Server", err)
}
defer connection.Close()
filePath, err := filepath.Abs(args[1])
if err != nil {
fmt.Println("Could Not get path to file", args[1])
Log.Fatal("Failed to get path to file", err)
}
serverClient := pb.NewFileserverClient(connection)
response, err := serverClient.UnServeFile(context.Background(),
&pb.UnServeRequest{
Uuid: uuid,
Pool: pool,
FilePath: filePath,
})
if err != nil {
fmt.Println("Unable to remove to Discovery Share Server")
Log.Fatal("Couldn't remove file from Discovery Share Server", err)
}
fmt.Println(response.ServeResponse)
}