-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6df820b
commit f79b04a
Showing
4 changed files
with
166 additions
and
127 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,58 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func copyFile(src string, dest string) error { | ||
info, err := os.Stat(src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// if it's a dir, just re-create it in build/ | ||
if info.IsDir() { | ||
err := os.Mkdir(dest, info.Mode()) | ||
if err != nil && !errors.Is(err, os.ErrExist) { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// open input | ||
in, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer in.Close() | ||
|
||
// create output | ||
fh, err := os.Create(dest) | ||
if err != nil { | ||
return err | ||
} | ||
defer fh.Close() | ||
|
||
// match file permissions | ||
err = fh.Chmod(info.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// copy content | ||
_, err = io.Copy(fh, in) | ||
return err | ||
} | ||
|
||
func copyDirRecursively(src string, dst string) error { | ||
return filepath.WalkDir(src, func(path string, d fs.DirEntry, err error) error { | ||
outpath := dst + strings.TrimPrefix(path, src) | ||
return copyFile(path, outpath) | ||
}) | ||
} |
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
Oops, something went wrong.