mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-09 13:00:53 +01:00
add stat call
This commit is contained in:
parent
3240b128e1
commit
573ca55c50
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user