MCPcopy
hub / github.com/kopia/kopia / Write

Method Write

internal/logfile/logfile.go:430–477  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

428}
429
430func (w *onDemandFile) Write(b []byte) (int, error) {
431 w.mu.Lock()
432 defer w.mu.Unlock()
433
434 // close current file if we'd overflow on next write.
435 if w.f != nil && w.currentSegmentSize+len(b) > w.maxSegmentSize {
436 w.closeSegmentAndSweepLocked()
437 }
438
439 // open file if we don't have it yet
440 if w.f == nil {
441 var baseName, ext string
442
443 p := strings.LastIndex(w.logFileBaseName, ".")
444 if p < 0 {
445 ext = ""
446 baseName = w.logFileBaseName
447 } else {
448 ext = w.logFileBaseName[p:]
449 baseName = w.logFileBaseName[0:p]
450 }
451
452 w.currentSegmentFilename = fmt.Sprintf("%s.%d%s", baseName, w.segmentCounter, ext)
453 w.segmentCounter++
454 w.currentSegmentSize = 0
455
456 lf := filepath.Join(w.logDir, w.currentSegmentFilename)
457
458 f, err := os.Create(lf) //nolint:gosec
459 if err != nil {
460 return 0, errors.Wrap(err, "unable to open log file")
461 }
462
463 w.f = f
464
465 if w.symlinkName != "" {
466 symlink := filepath.Join(w.logDir, w.symlinkName)
467 _ = os.Remove(symlink) // best-effort remove
468 _ = os.Symlink(w.currentSegmentFilename, symlink) // best-effort symlink
469 }
470 }
471
472 n, err := w.f.Write(b)
473 w.currentSegmentSize += n
474
475 //nolint:wrapcheck
476 return n, err
477}

Callers 15

SendMethod · 0.45
hashOfFunction · 0.45
deriveKeyFromPasswordMethod · 0.45
outputEntryMethod · 0.45
oidForContentFunction · 0.45
copyBufferFunction · 0.45
remoteRepositoryTestFunction · 0.45
mustWriteObjectFunction · 0.45
sha256KeyFunction · 0.45
benchmarkInternalMapFunction · 0.45

Calls 4

LockMethod · 0.65
UnlockMethod · 0.65
RemoveMethod · 0.65

Tested by 13

oidForContentFunction · 0.36
remoteRepositoryTestFunction · 0.36
mustWriteObjectFunction · 0.36
sha256KeyFunction · 0.36
benchmarkInternalMapFunction · 0.36
benchmarkSyncMapFunction · 0.36
sha256KeyFunction · 0.36
benchmarkMapFunction · 0.36
BenchmarkSetFunction · 0.36
TestStreamingFileFunction · 0.36