-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a simple program to copy the plugin binary, so that we will not depend on busybox. Signed-off-by: Daniel Jiang <jiangd@vmware.com>
- Loading branch information
1 parent
88f64da
commit 50a0b2f
Showing
2 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 3 { | ||
fmt.Println( | ||
`Error: This command requires two arguments. | ||
Usage: cp-plugin src dst`) | ||
os.Exit(1) | ||
} | ||
src, dst := os.Args[1], os.Args[2] | ||
fmt.Printf("Copying %s to %s ... ", src, dst) | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer srcFile.Close() | ||
if _, err := os.Stat(dst); errors.Is(err, os.ErrNotExist) { | ||
_, err = os.Create(dst) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
dstFile, err := os.OpenFile(dst, os.O_WRONLY, 0755) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer dstFile.Close() | ||
buf := make([]byte, 1024*128) | ||
_, err = io.CopyBuffer(dstFile, srcFile, buf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
os.Chmod(dst, 0755) | ||
fmt.Println("done.") | ||
} |