CopyFile copies content into a file beneath the root. Creation permissions follow [Root.Create].
(name string, src io.Reader, filePerm, dirPerm os.FileMode, replace bool)
| 251 | // CopyFile copies content into a file beneath the root. |
| 252 | // Creation permissions follow [Root.Create]. |
| 253 | func (r *Root) CopyFile(name string, src io.Reader, filePerm, dirPerm os.FileMode, replace bool) (err error) { |
| 254 | file, err := r.Create(name, filePerm, dirPerm, replace) |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | defer func() { |
| 259 | if closeErr := file.Close(); err == nil && closeErr != nil { |
| 260 | err = closeErr |
| 261 | } |
| 262 | }() |
| 263 | |
| 264 | _, err = io.Copy(file, src) |
| 265 | return err |
| 266 | } |
| 267 | |
| 268 | func (r *Root) localPath(name string) (string, error) { |
| 269 | return validateChildPath(name) |