add stat call

This commit is contained in:
sawka 2023-02-06 00:29:33 -08:00
parent 3240b128e1
commit 573ca55c50

View File

@ -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