file

package
v1.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RLockFileSuffix = ".rlock"
	LockFileSuffix  = ".lock"
	TempFileSuffix  = ".temp"
)
View Source
const DefaultRetryDelay = 10 * time.Millisecond
View Source
const DefaultWaitTimeout = 10 * time.Second

Variables

This section is empty.

Functions

func Exists

func Exists(path string) bool

func GetTimeoutContext

func GetTimeoutContext(ctx context.Context, waitTimeOut time.Duration) (context.Context, context.CancelFunc)

func LockExists

func LockExists(path string) bool

func LockFilePath

func LockFilePath(path string) string

func NewAlreadyExistError

func NewAlreadyExistError(message string) error

func NewCompositeError

func NewCompositeError(err1 error, err2 error) error

func NewContextCanceled

func NewContextCanceled() error

func NewContextDone

func NewContextDone(message string) error

func NewForcedUnlockError

func NewForcedUnlockError(errs []error) error

func NewIOError

func NewIOError(message string) error

func NewLockError

func NewLockError(message string) error

func NewNotExistError

func NewNotExistError(message string) error

func NewTimeoutError

func NewTimeoutError(path string) error

func ParseError

func ParseError(err error) error

func RLockExists

func RLockExists(path string) bool

func RLockFilePath

func RLockFilePath(path string) string

func RandomString

func RandomString(length int) string

func TempFilePath

func TempFilePath(path string) string

Types

type AlreadyExistError

type AlreadyExistError struct {
	// contains filtered or unexported fields
}

func (AlreadyExistError) Error

func (e AlreadyExistError) Error() string

type CompositeError

type CompositeError struct {
	// contains filtered or unexported fields
}

func (CompositeError) Error

func (e CompositeError) Error() string

type Container

type Container struct {
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer() *Container

func (*Container) Add

func (c *Container) Add(path string, handler *Handler) error

func (*Container) Close

func (c *Container) Close(h *Handler) error

func (*Container) CloseAll

func (c *Container) CloseAll() error

func (*Container) CloseAllWithErrors

func (c *Container) CloseAllWithErrors() error

func (*Container) CloseWithErrors

func (c *Container) CloseWithErrors(h *Handler) (err error)

func (*Container) Commit

func (c *Container) Commit(h *Handler) error

func (*Container) CreateHandlerForCreate

func (c *Container) CreateHandlerForCreate(path string) (*Handler, error)

func (*Container) CreateHandlerForRead

func (c *Container) CreateHandlerForRead(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func (*Container) CreateHandlerForUpdate

func (c *Container) CreateHandlerForUpdate(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func (*Container) CreateHandlerWithoutLock

func (c *Container) CreateHandlerWithoutLock(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func (*Container) Keys

func (c *Container) Keys() []string

func (*Container) Remove

func (c *Container) Remove(path string)

type ContextCanceled

type ContextCanceled struct {
	// contains filtered or unexported fields
}

func (ContextCanceled) Error

func (e ContextCanceled) Error() string

type ContextDone

type ContextDone struct {
	// contains filtered or unexported fields
}

func (ContextDone) Error

func (e ContextDone) Error() string

type ControlFile

type ControlFile struct {
	// contains filtered or unexported fields
}

func CreateControlFileContext

func CreateControlFileContext(ctx context.Context, filePath string, fileType ControlFileType, retryDelay time.Duration) (*ControlFile, error)

func NewControlFile

func NewControlFile(path string, fp *os.File) *ControlFile

func TryCreateLockFile

func TryCreateLockFile(filePath string) (*ControlFile, error)

func TryCreateRLockFile

func TryCreateRLockFile(filePath string) (controlFile *ControlFile, err error)

func TryCreateTempFile

func TryCreateTempFile(filePath string) (*ControlFile, error)

func (*ControlFile) Close

func (m *ControlFile) Close() error

func (*ControlFile) CloseWithErrors

func (m *ControlFile) CloseWithErrors() []error

type ControlFileType

type ControlFileType int
const (
	RLock ControlFileType = iota
	Lock
	Temporary
)

func (ControlFileType) String

func (t ControlFileType) String() string

type ForcedUnlockError

type ForcedUnlockError struct {
	Errors []error
}

func (ForcedUnlockError) Error

func (e ForcedUnlockError) Error() string

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandlerForCreate

func NewHandlerForCreate(path string) (*Handler, error)

func NewHandlerForRead

func NewHandlerForRead(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func NewHandlerForUpdate

func NewHandlerForUpdate(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func NewHandlerWithoutLock

func NewHandlerWithoutLock(ctx context.Context, path string, defaultWaitTimeout time.Duration, retryDelay time.Duration) (*Handler, error)

func (*Handler) CreateControlFileContext

func (h *Handler) CreateControlFileContext(ctx context.Context, fileType ControlFileType, retryDelay time.Duration) error

func (*Handler) File

func (h *Handler) File() *os.File

func (*Handler) FileForUpdate

func (h *Handler) FileForUpdate() (*os.File, error)

func (*Handler) Path

func (h *Handler) Path() string

type IOError

type IOError struct {
	// contains filtered or unexported fields
}

func (IOError) Error

func (e IOError) Error() string

type LockError

type LockError struct {
	// contains filtered or unexported fields
}

func (LockError) Error

func (e LockError) Error() string

type NotExistError

type NotExistError struct {
	// contains filtered or unexported fields
}

func (NotExistError) Error

func (e NotExistError) Error() string

type OpenType

type OpenType int
const (
	ForRead OpenType = iota
	ForCreate
	ForUpdate
)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader, headLen int) (*Reader, error)

func (*Reader) HeadBytes

func (r *Reader) HeadBytes() (io.ReadSeeker, error)

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) Size

func (r *Reader) Size() int64

type TimeoutError

type TimeoutError struct {
	// contains filtered or unexported fields
}

func (TimeoutError) Error

func (e TimeoutError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL