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
25
main.go
25
main.go
@ -545,23 +545,40 @@ 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)
|
||||
|
||||
if _, err := io.Copy(w, r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func build(path string, w io.Writer, vars Vars) error {
|
||||
if Ignore.MatchesPath(path) {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user