mirror of
https://git.mills.io/prologic/zs
synced 2024-11-25 06:46:11 +03:00
Fix and preserve file permissions when copying raw files (Fixes #15)
This commit is contained in:
parent
dc33985231
commit
045940e292
27
main.go
27
main.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user