package fileutil

Import Path
	github.com/coreos/etcd/pkg/fileutil (on go.dev)

Dependency Relation
	imports 11 packages, and imported by one package

Involved Source Files dir_unix.go Package fileutil implements utility functions related to files and paths. lock.go lock_flock.go lock_linux.go preallocate.go preallocate_unix.go purge.go sync_linux.go
Package-Level Type Names (only one)
/* sort by: | */
File *os.File Chdir changes the current working directory to the file, which must be a directory. If there is an error, it will be of type [*PathError]. Chmod changes the mode of the file to mode. If there is an error, it will be of type [*PathError]. Chown changes the numeric uid and gid of the named file. If there is an error, it will be of type [*PathError]. On Windows, it always returns the [syscall.EWINDOWS] error, wrapped in [*PathError]. Close closes the [File], rendering it unusable for I/O. On files that support [File.SetDeadline], any pending I/O operations will be canceled and return immediately with an [ErrClosed] error. Close will return an error if it has already been called. Fd returns the system file descriptor or handle referencing the open file. If f is closed, the descriptor becomes invalid. If f is garbage collected, a finalizer may close the descriptor, making it invalid; see [runtime.SetFinalizer] for more information on when a finalizer might be run. Do not close the returned descriptor; that could cause a later close of f to close an unrelated descriptor. Fd's behavior differs on some platforms: - On Unix and Windows, [File.SetDeadline] methods will stop working. - On Windows, the file descriptor will be disassociated from the Go runtime I/O completion port if there are no concurrent I/O operations on the file. For most uses prefer the f.SyscallConn method. Name returns the name of the file as presented to Open. It is safe to call Name after [Close]. Read reads up to len(b) bytes from the File and stores them in b. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF. ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF. ReadDir reads the contents of the directory associated with the file f and returns a slice of [DirEntry] values in directory order. Subsequent calls on the same file will yield later DirEntry records in the directory. If n > 0, ReadDir returns at most n DirEntry records. In this case, if ReadDir returns an empty slice, it will return an error explaining why. At the end of a directory, the error is [io.EOF]. If n <= 0, ReadDir returns all the DirEntry records remaining in the directory. When it succeeds, it returns a nil error (not io.EOF). ReadFrom implements io.ReaderFrom. Readdir reads the contents of the directory associated with file and returns a slice of up to n [FileInfo] values, as would be returned by [Lstat], in directory order. Subsequent calls on the same file will yield further FileInfos. If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is [io.EOF]. If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error. Most clients are better served by the more efficient ReadDir method. Readdirnames reads the contents of the directory associated with file and returns a slice of up to n names of files in the directory, in directory order. Subsequent calls on the same file will yield further names. If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is [io.EOF]. If n <= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error. Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with [O_APPEND] is not specified. SetDeadline sets the read and write deadlines for a File. It is equivalent to calling both SetReadDeadline and SetWriteDeadline. Only some kinds of files support setting a deadline. Calls to SetDeadline for files that do not support deadlines will return ErrNoDeadline. On most systems ordinary files do not support deadlines, but pipes do. A deadline is an absolute time after which I/O operations fail with an error instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future. If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). That error implements the Timeout method, and calling the Timeout method will return true, but there are other possible errors for which the Timeout will return true even if the deadline has not been exceeded. An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls. A zero value for t means I/O operations will not time out. SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out. Not all files support setting deadlines; see SetDeadline. SetWriteDeadline sets the deadline for any future Write calls and any currently-blocked Write call. Even if Write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out. Not all files support setting deadlines; see SetDeadline. Stat returns the [FileInfo] structure describing file. If there is an error, it will be of type [*PathError]. Sync commits the current contents of the file to stable storage. Typically, this means flushing the file system's in-memory copy of recently written data to disk. SyscallConn returns a raw file. This implements the syscall.Conn interface. Truncate changes the size of the file. It does not change the I/O offset. If there is an error, it will be of type [*PathError]. Write writes len(b) bytes from b to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b). WriteAt writes len(b) bytes to the File starting at byte offset off. It returns the number of bytes written and an error, if any. WriteAt returns a non-nil error when n != len(b). If file was opened with the [O_APPEND] flag, WriteAt returns an error. WriteString is like Write, but writes the contents of string s rather than a slice of bytes. WriteTo implements io.WriterTo. LockedFile : github.com/apache/arrow-go/v18/arrow/ipc.ReadAtSeeker LockedFile : github.com/apache/arrow-go/v18/internal/utils.Reader LockedFile : github.com/apache/arrow-go/v18/parquet.ReaderAtSeeker LockedFile : github.com/gobwas/ws.HandshakeHeader LockedFile : github.com/miekg/dns.Writer LockedFile : github.com/pion/datachannel.ReadDeadliner LockedFile : github.com/pion/datachannel.WriteDeadliner LockedFile : github.com/pion/stun.Connection LockedFile : github.com/pion/stun/v3.Connection LockedFile : github.com/polarsignals/frostdb.Sync LockedFile : github.com/polarsignals/frostdb/query/logicalplan.Named LockedFile : github.com/polarsignals/wal/types.ReadableFile LockedFile : github.com/polarsignals/wal/types.WritableFile LockedFile : github.com/prometheus/common/expfmt.Closer LockedFile : go.uber.org/zap.Sink LockedFile : go.uber.org/zap/zapcore.WriteSyncer LockedFile : internal/bisect.Writer LockedFile : io.Closer LockedFile : io.ReadCloser LockedFile : io.Reader LockedFile : io.ReaderAt LockedFile : io.ReaderFrom LockedFile : io.ReadSeekCloser LockedFile : io.ReadSeeker LockedFile : io.ReadWriteCloser LockedFile : io.ReadWriter LockedFile : io.ReadWriteSeeker LockedFile : io.Seeker LockedFile : io.StringWriter LockedFile : io.WriteCloser LockedFile : io.Writer LockedFile : io.WriterAt LockedFile : io.WriterTo LockedFile : io.WriteSeeker LockedFile : io/fs.File LockedFile : io/fs.ReadDirFile LockedFile : mime/multipart.File LockedFile : net/http.File LockedFile : syscall.Conn func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)
Package-Level Functions (total 15)
CheckDirPermission checks permission on an existing dir. Returns error if dir is empty or exist with a different permission than specified.
CreateDirAll is similar to TouchDirAll but returns error if the deepest directory was not empty.
func Exist(name string) bool
Fdatasync is similar to fsync(), but does not flush modified metadata unless that metadata is needed in order to allow a subsequent data retrieval to be correctly handled.
Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.
IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable.
func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)
OpenDir opens a directory for syncing.
Preallocate tries to allocate the space for given file. This operation is only supported on linux by a few filesystems (btrfs, ext4, etc.). If the operation is unsupported, no error will be returned. Otherwise, the error encountered will be returned.
func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error
func PurgeFileWithDoneNotify(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error)
ReadDir returns the filenames in the given directory in sorted order.
TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory does not exists. TouchDirAll also ensures the given directory is writable.
func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)
ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily shorten the length of the file.
Package-Level Variables (only one)
Package-Level Constants (total 5)
This used to call syscall.Flock() but that call fails with EBADF on NFS. An alternative is lockf() which works on NFS but that call lets a process lock the same file twice. Instead, use Linux's non-standard open file descriptor locks which will block if the process already holds the file lock. constants from /usr/include/bits/fcntl-linux.h
This used to call syscall.Flock() but that call fails with EBADF on NFS. An alternative is lockf() which works on NFS but that call lets a process lock the same file twice. Instead, use Linux's non-standard open file descriptor locks which will block if the process already holds the file lock. constants from /usr/include/bits/fcntl-linux.h
This used to call syscall.Flock() but that call fails with EBADF on NFS. An alternative is lockf() which works on NFS but that call lets a process lock the same file twice. Instead, use Linux's non-standard open file descriptor locks which will block if the process already holds the file lock. constants from /usr/include/bits/fcntl-linux.h
PrivateDirMode grants owner to make/remove files inside the directory.
PrivateFileMode grants owner to read/write a file.