MCPcopy
hub / github.com/syncthing/syncthing / newRotatedFile

Function newRotatedFile

cmd/syncthing/monitor.go:333–355  ·  view source on GitHub ↗
(name string, create createFn, maxSize int64, maxFiles int)

Source from the content-addressed store, hash-verified

331type createFn func(name string) (io.WriteCloser, error)
332
333func newRotatedFile(name string, create createFn, maxSize int64, maxFiles int) (*rotatedFile, error) {
334 var size int64
335 if info, err := os.Lstat(name); err != nil {
336 if !os.IsNotExist(err) {
337 return nil, err
338 }
339 size = 0
340 } else {
341 size = info.Size()
342 }
343 writer, err := create(name)
344 if err != nil {
345 return nil, err
346 }
347 return &rotatedFile{
348 name: name,
349 create: create,
350 maxSize: maxSize,
351 maxFiles: maxFiles,
352 currentFile: writer,
353 currentSize: size,
354 }, nil
355}
356
357func (r *rotatedFile) Write(bs []byte) (int, error) {
358 // Check if we're about to exceed the max size, and if so close this

Callers 2

TestRotatedFileFunction · 0.85
monitorMainMethod · 0.85

Calls 2

LstatMethod · 0.65
SizeMethod · 0.65

Tested by 1

TestRotatedFileFunction · 0.68