Fix and preserve file permissions when copying raw files (Fixes #15)

This commit is contained in:
James Mills 2023-04-01 21:18:28 +10:00
parent dc33985231
commit 045940e292
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

27
main.go
View File

@ -545,21 +545,38 @@ func buildHTML(path string, w io.Writer, vars Vars) error {
// Copies file as is from path to writer
func buildRaw(path string, w io.Writer) error {
in, err := os.Open(path)
r, err := os.Open(path)
if err != nil {
return err
}
defer in.Close()
defer r.Close()
if w == nil {
out, err := os.Create(filepath.Join(PUBDIR, path))
stat, err := os.Stat(path)
if err != nil {
return err
}
fn := filepath.Join(PUBDIR, path)
out, err := os.Create(fn)
if err != nil {
return err
}
defer out.Close()
if err := os.Chmod(fn, stat.Mode()); err != nil {
return err
}
w = out
}
_, err = io.Copy(w, in)
return err
if _, err := io.Copy(w, r); err != nil {
return err
}
return nil
}
func build(path string, w io.Writer, vars Vars) error {