This repository was archived by the owner on Jul 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 11package bootkube
22
33import (
4- "fmt"
5- "io/ioutil"
4+ "io"
65 "os"
76 "path/filepath"
87 "strings"
@@ -62,20 +61,23 @@ func (b *bootstrapControlPlane) Teardown() error {
6261// copyFile copies a single file from src to dst. Returns an error if overwrite is true and dst
6362// exists, or if any I/O error occurs during copying.
6463func copyFile (src , dst string , overwrite bool ) error {
64+ flags := os .O_CREATE | os .O_WRONLY
6565 if ! overwrite {
66- fi , err := os .Stat (dst )
67- if fi != nil {
68- return fmt .Errorf ("file already exists: %v" , dst )
69- }
70- if ! os .IsNotExist (err ) {
71- return err
72- }
66+ flags |= os .O_EXCL
67+ }
68+
69+ dstfile , err := os .OpenFile (dst , flags , os .FileMode (0600 ))
70+ if err != nil {
71+ return err
7372 }
74- data , err := ioutil .ReadFile (src )
73+
74+ srcfile , err := os .Open (src )
7575 if err != nil {
7676 return err
7777 }
78- return ioutil .WriteFile (dst , data , os .FileMode (0600 ))
78+
79+ _ , err = io .Copy (dstfile , srcfile )
80+ return err
7981}
8082
8183// copyDirectory copies srcDir to dstDir recursively. It returns the paths of files (not
You can’t perform that action at this time.
0 commit comments