copyReader copies from an io.Reader into a file, using umask to create the dst file
(dst string, src io.Reader, fmode, umask os.FileMode, fileSizeLimit int64)
| 32 | |
| 33 | // copyReader copies from an io.Reader into a file, using umask to create the dst file |
| 34 | func copyReader(dst string, src io.Reader, fmode, umask os.FileMode, fileSizeLimit int64) error { |
| 35 | dstF, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fmode) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | defer dstF.Close() |
| 40 | |
| 41 | if fileSizeLimit > 0 { |
| 42 | src = io.LimitReader(src, fileSizeLimit) |
| 43 | } |
| 44 | |
| 45 | _, err = io.Copy(dstF, src) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | // Explicitly chmod; the process umask is unconditionally applied otherwise. |
| 51 | // We'll mask the mode with our own umask, but that may be different than |
| 52 | // the process umask |
| 53 | return os.Chmod(dst, mode(fmode, umask)) |
| 54 | } |
| 55 | |
| 56 | // copyFile copies a file in chunks from src path to dst path, using umask to create the dst file |
| 57 | func copyFile(ctx context.Context, dst, src string, disableSymlinks bool, fmode, umask os.FileMode) (int64, error) { |
no test coverage detected