MCPcopy
hub / github.com/kopia/kopia / compareFiles

Method compareFiles

internal/diff/diff.go:327–368  ·  view source on GitHub ↗
(ctx context.Context, f1, f2 fs.File, fname string)

Source from the content-addressed store, hash-verified

325}
326
327func (c *Comparer) compareFiles(ctx context.Context, f1, f2 fs.File, fname string) error {
328 if c.DiffCommand == "" {
329 return nil
330 }
331
332 oldName := "/dev/null"
333 newName := "/dev/null"
334
335 if f1 != nil {
336 oldName = filepath.Join("old", fname)
337 oldFile := filepath.Join(c.tmpDir, oldName)
338
339 if err := downloadFile(ctx, f1, oldFile); err != nil {
340 return errors.Wrap(err, "error downloading old file")
341 }
342
343 defer os.Remove(oldFile) //nolint:errcheck
344 }
345
346 if f2 != nil {
347 newName = filepath.Join("new", fname)
348 newFile := filepath.Join(c.tmpDir, newName)
349
350 if err := downloadFile(ctx, f2, newFile); err != nil {
351 return errors.Wrap(err, "error downloading new file")
352 }
353 defer os.Remove(newFile) //nolint:errcheck
354 }
355
356 var args []string
357
358 args = append(args, c.DiffArguments...)
359 args = append(args, oldName, newName)
360
361 cmd := exec.CommandContext(ctx, c.DiffCommand, args...) //nolint:gosec
362 cmd.Dir = c.tmpDir
363 cmd.Stdout = c.out
364 cmd.Stderr = c.out
365 cmd.Run() //nolint:errcheck
366
367 return nil
368}
369
370func downloadFile(ctx context.Context, f fs.File, fname string) error {
371 if err := os.MkdirAll(filepath.Dir(fname), dirMode); err != nil {

Callers 1

compareEntryMethod · 0.95

Calls 3

downloadFileFunction · 0.85
RemoveMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected