-
Notifications
You must be signed in to change notification settings - Fork 0
/
mountcmd.go
37 lines (30 loc) · 1.16 KB
/
mountcmd.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
package commands
import (
"fmt"
"github.com/cpssd/paranoid/libpfs/returncodes"
"io/ioutil"
"path"
"path/filepath"
)
//MountCommand is used to notify a pfs paranoidDirectory it has been mounted.
func MountCommand(paranoidDirectory, ip, port, mountPoint string) (returnCode returncodes.Code, returnError error) {
Log.Info("mount command called")
Log.Verbose("mount : given paranoidDirectory = " + paranoidDirectory)
err := ioutil.WriteFile(path.Join(paranoidDirectory, "meta", "ip"), []byte(ip), 0600)
if err != nil {
return returncodes.EUNEXPECTED, fmt.Errorf("error writing ip: %s", err)
}
err = ioutil.WriteFile(path.Join(paranoidDirectory, "meta", "port"), []byte(port), 0600)
if err != nil {
return returncodes.EUNEXPECTED, fmt.Errorf("error writing port: %s", err)
}
mountPoint, err = filepath.Abs(mountPoint)
if err != nil {
return returncodes.EUNEXPECTED, fmt.Errorf("error getting absolute path of mountpoint: %s", err)
}
err = ioutil.WriteFile(path.Join(paranoidDirectory, "meta", "mountpoint"), []byte(mountPoint), 0600)
if err != nil {
return returncodes.EUNEXPECTED, fmt.Errorf("error writing mountpoint: %s", err)
}
return returncodes.OK, nil
}