MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / copyLocalFile

Function copyLocalFile

rest/x509_utils_test.go:453–470  ·  view source on GitHub ↗

copyLocalFile takes in a full source filepath and a destination directory. The destination directory will be created in full if it does not exist, the file will be copied, and then the read and execute permissions set.

(sourceFilepath, destinationDirectory string)

Source from the content-addressed store, hash-verified

451// copyLocalFile takes in a full source filepath and a destination directory.
452// The destination directory will be created in full if it does not exist, the file will be copied, and then the read and execute permissions set.
453func copyLocalFile(sourceFilepath, destinationDirectory string) error {
454
455 // make destination directory if it doesn't exist
456 err := runCmd("mkdir", "-p", destinationDirectory)
457 if err != nil {
458 return err
459 }
460
461 // copy the file
462 err = runCmd("cp", sourceFilepath, destinationDirectory)
463 if err != nil {
464 return err
465 }
466
467 // make the file we just copied readable and executable (required for Couchbase server to use the certs)
468 return runCmd("chmod", "-R", "a+rwx", filepath.Join(destinationDirectory, filepath.Base(sourceFilepath)))
469
470}
471
472// runCmd runs a command and returns error if the command fails
473func runCmd(arg ...string) error {

Callers 1

Calls 1

runCmdFunction · 0.85

Tested by

no test coverage detected