@@ -22,8 +22,12 @@ func supportsFuse() bool {
2222 return err1 == nil && err2 == nil && err3 == nil && err4 == nil
2323}
2424
25+ type KBFSOperation struct {
26+ KeybaseBinaryPath string
27+ }
28+
2529// Returns whether the given KBFS file exists
26- func KBFSFileExists (kbfsFilename string ) (bool , error ) {
30+ func ( ko * KBFSOperation ) KBFSFileExists (kbfsFilename string ) (bool , error ) {
2731 if supportsFuse () {
2832 // Note that this code is not tested via integration tests since fuse does not run in docker. Handle with care.
2933 _ , err := os .Stat (kbfsFilename )
@@ -36,7 +40,7 @@ func KBFSFileExists(kbfsFilename string) (bool, error) {
3640 return false , err
3741 }
3842
39- cmd := exec .Command ("keybase" , "fs" , "stat" , kbfsFilename )
43+ cmd := exec .Command (ko . KeybaseBinaryPath , "fs" , "stat" , kbfsFilename )
4044 bytes , err := cmd .CombinedOutput ()
4145 if err == nil {
4246 return true , nil
@@ -48,12 +52,12 @@ func KBFSFileExists(kbfsFilename string) (bool, error) {
4852}
4953
5054// Reads the specified KBFS file into a byte array
51- func KBFSRead (kbfsFilename string ) ([]byte , error ) {
55+ func ( ko * KBFSOperation ) KBFSRead (kbfsFilename string ) ([]byte , error ) {
5256 if supportsFuse () {
5357 // Note that this code is not tested via integration tests since fuse does not run in docker. Handle with care.
5458 return ioutil .ReadFile (kbfsFilename )
5559 }
56- cmd := exec .Command ("keybase" , "fs" , "read" , kbfsFilename )
60+ cmd := exec .Command (ko . KeybaseBinaryPath , "fs" , "read" , kbfsFilename )
5761 bytes , err := cmd .CombinedOutput ()
5862 if err != nil {
5963 return nil , fmt .Errorf ("failed to read %s: %s (%v)" , kbfsFilename , strings .TrimSpace (string (bytes )), err )
@@ -62,8 +66,8 @@ func KBFSRead(kbfsFilename string) ([]byte, error) {
6266}
6367
6468// Delete the specified KBFS file
65- func KBFSDelete (filename string ) error {
66- cmd := exec .Command ("keybase" , "fs" , "rm" , filename )
69+ func ( ko * KBFSOperation ) KBFSDelete (filename string ) error {
70+ cmd := exec .Command (ko . KeybaseBinaryPath , "fs" , "rm" , filename )
6771 bytes , err := cmd .CombinedOutput ()
6872 if err != nil {
6973 return fmt .Errorf ("failed to delete the file at %s: %s (%v)" , filename , strings .TrimSpace (string (bytes )), err )
@@ -73,20 +77,20 @@ func KBFSDelete(filename string) error {
7377
7478// Write contents to the specified KBFS file. If appendToFile, appends onto the end of the file. Otherwise, overwrites
7579// and truncates the file.
76- func KBFSWrite (filename string , contents string , appendToFile bool ) error {
80+ func ( ko * KBFSOperation ) KBFSWrite (filename string , contents string , appendToFile bool ) error {
7781 var cmd * exec.Cmd
7882 if appendToFile {
7983 // `keybase fs write --append` only works if the file already exists so create it if it does not exist
80- exists , err := KBFSFileExists (filename )
84+ exists , err := ko . KBFSFileExists (filename )
8185 if ! exists || err != nil {
82- err = KBFSWrite (filename , "" , false )
86+ err = ko . KBFSWrite (filename , "" , false )
8387 if err != nil {
8488 return err
8589 }
8690 }
87- cmd = exec .Command ("keybase" , "fs" , "write" , "--append" , filename )
91+ cmd = exec .Command (ko . KeybaseBinaryPath , "fs" , "write" , "--append" , filename )
8892 } else {
89- cmd = exec .Command ("keybase" , "fs" , "write" , filename )
93+ cmd = exec .Command (ko . KeybaseBinaryPath , "fs" , "write" , filename )
9094 }
9195
9296 cmd .Stdin = strings .NewReader (string (contents ))
@@ -98,8 +102,8 @@ func KBFSWrite(filename string, contents string, appendToFile bool) error {
98102}
99103
100104// List KBFS files in the given KBFS path
101- func KBFSList (path string ) ([]string , error ) {
102- cmd := exec .Command ("keybase" , "fs" , "ls" , "-1" , "--nocolor" , path )
105+ func ( ko * KBFSOperation ) KBFSList (path string ) ([]string , error ) {
106+ cmd := exec .Command (ko . KeybaseBinaryPath , "fs" , "ls" , "-1" , "--nocolor" , path )
103107 output , err := cmd .CombinedOutput ()
104108 if err != nil {
105109 return nil , fmt .Errorf ("failed to list files in /keybase/team/: %s (%v)" , strings .TrimSpace (string (output )), err )
0 commit comments