(ctx context.Context, pkg, out *packageFS, path string)
| 191 | } |
| 192 | |
| 193 | func (d *DerivationBuilder) copyFile(ctx context.Context, pkg, out *packageFS, path string) error { |
| 194 | srcFile, err := pkg.Open(path) |
| 195 | if err != nil { |
| 196 | return err |
| 197 | } |
| 198 | defer srcFile.Close() |
| 199 | |
| 200 | src := bufio.NewReader(srcFile) |
| 201 | if d.needsGlibcPatch(src, path) { |
| 202 | srcPath, err := pkg.OSPath(path) |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 | dstPath, err := out.OSPath(path) |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | // No need to copy the file, patchelf will do it for us. |
| 211 | return d.glibcPatcher.patch(ctx, srcPath, dstPath) |
| 212 | } |
| 213 | |
| 214 | stat, err := srcFile.Stat() |
| 215 | if err != nil { |
| 216 | return err |
| 217 | } |
| 218 | |
| 219 | // We only need to copy the executable permissions of a file. |
| 220 | // Nix ends up making everything in the store read-only after |
| 221 | // the build is done. |
| 222 | perm := fs.FileMode(0o666) |
| 223 | if isExecutable(stat.Mode()) { |
| 224 | perm = fs.FileMode(0o777) |
| 225 | } |
| 226 | |
| 227 | dstPath, err := out.OSPath(path) |
| 228 | if err != nil { |
| 229 | return err |
| 230 | } |
| 231 | dst, err := os.OpenFile(dstPath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, perm) |
| 232 | if err != nil { |
| 233 | return err |
| 234 | } |
| 235 | defer dst.Close() |
| 236 | |
| 237 | _, err = io.Copy(dst, src) |
| 238 | if err != nil { |
| 239 | return err |
| 240 | } |
| 241 | |
| 242 | for _, patch := range d.bytePatches[path] { |
| 243 | _, err := dst.WriteAt(patch.data, patch.offset) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | } |
| 248 | return dst.Close() |
| 249 | } |
| 250 |
no test coverage detected