diff --git a/pkg/cirfile/cirfile.go b/pkg/cirfile/cirfile.go index 51c8cbe7..797b09bd 100644 --- a/pkg/cirfile/cirfile.go +++ b/pkg/cirfile/cirfile.go @@ -32,6 +32,14 @@ type File struct { FlockStatus int } +type Stat struct { + Location string + Version byte + MaxSize int64 + FileOffset int64 + DataSize int64 +} + func (f *File) flock(ctx context.Context, lockType int) error { err := syscall.Flock(int(f.OSFile.Fd()), lockType|syscall.LOCK_NB) if err == nil { @@ -98,6 +106,25 @@ func OpenCirFile(fileName string) (*File, error) { return rtn, nil } +func StatCirFile(ctx context.Context, fileName string) (*Stat, error) { + file, err := OpenCirFile(fileName) + if err != nil { + return nil, err + } + defer file.Close() + fileOffset, dataSize, err := file.GetStartOffsetAndSize(ctx) + if err != nil { + return nil, err + } + return &Stat{ + Location: fileName, + Version: file.Version, + MaxSize: file.MaxSize, + FileOffset: fileOffset, + DataSize: dataSize, + }, nil +} + // if the file already exists, it is an error. // there is a race condition if two goroutines try to create the same file between Stat() and Create(), so // they both might get no error, but only one file will be valid. if this is a concern, this call