mirror of
https://git.mills.io/prologic/zs
synced 2024-11-22 05:16: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
|
// Copies file as is from path to writer
|
||||||
func buildRaw(path string, w io.Writer) error {
|
func buildRaw(path string, w io.Writer) error {
|
||||||
in, err := os.Open(path)
|
r, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer in.Close()
|
defer r.Close()
|
||||||
|
|
||||||
if w == nil {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
|
if err := os.Chmod(fn, stat.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
w = out
|
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 {
|
func build(path string, w io.Writer, vars Vars) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user