MCPcopy Index your code
hub / github.com/jetify-com/devbox / copyFile

Method copyFile

internal/patchpkg/builder.go:193–249  ·  view source on GitHub ↗
(ctx context.Context, pkg, out *packageFS, path string)

Source from the content-addressed store, hash-verified

191}
192
193func (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

Callers 2

buildMethod · 0.95
findCUDAMethod · 0.95

Calls 4

needsGlibcPatchMethod · 0.95
isExecutableFunction · 0.85
OSPathMethod · 0.80
patchMethod · 0.80

Tested by

no test coverage detected