Documentation ¶
Overview ¶
Package osutil implements utilities for native OS support.
Index ¶
- Variables
- func Copy(filesystem fs.Filesystem, from, to string) (err error)
- func GetLans() ([]*net.IPNet, error)
- func GetLatencyForURL(addr string) (time.Duration, error)
- func HideConsole()
- func InWritableDir(fn func(string) error, fs fs.Filesystem, path string) error
- func IsWindowsExecutable(path string) bool
- func MaximizeOpenFileLimit() (int, error)
- func NativeFilename(s string) string
- func NormalizedFilename(s string) string
- func Rename(filesystem fs.Filesystem, from, to string) error
- func ResolveInterfaceAddresses(network, nameOrMac string) []string
- func TCPPing(address string) (time.Duration, error)
- func TempFile(filesystem fs.Filesystem, dir, prefix string) (f fs.File, err error)
- func TraversesSymlink(filesystem fs.Filesystem, name string) error
- func TryRename(filesystem fs.Filesystem, from, to string) error
- type AtomicWriter
- type NotADirectoryError
- type ReplacingWriter
- type TraversesSymlinkError
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("write to closed writer") TempPrefix = ".syncthing.tmp." )
Functions ¶
func Copy ¶
func Copy(filesystem fs.Filesystem, from, to string) (err error)
Copy copies the file content from source to destination. Tries hard to succeed on various systems by temporarily tweaking directory permissions and removing the destination file when necessary.
func GetLatencyForURL ¶ added in v0.12.0
GetLatencyForURL parses the given URL, tries opening a TCP connection to it and returns the time it took to establish the connection.
func HideConsole ¶
func HideConsole()
func InWritableDir ¶
InWritableDir calls fn(path), while making sure that the directory containing `path` is writable for the duration of the call.
func IsWindowsExecutable ¶
IsWindowsExecutable returns true if the given path has an extension that is in the list of executable extensions.
func MaximizeOpenFileLimit ¶
MaximizeOpenFileLimit tries to set the resource limit RLIMIT_NOFILE (number of open file descriptors) to the max (hard limit), if the current (soft limit) is below the max. Returns the new (though possibly unchanged) limit, or an error if it could not be changed.
func NativeFilename ¶
func NormalizedFilename ¶
func Rename ¶
func Rename(filesystem fs.Filesystem, from, to string) error
Rename moves a temporary file to it's final place. Will make sure to delete the from file if the operation fails, so use only for situations like committing a temp file to it's final location. Tries hard to succeed on various systems by temporarily tweaking directory permissions and removing the destination file when necessary.
func ResolveInterfaceAddresses ¶ added in v0.14.37
ResolveInterfaceAddresses returns available addresses of the given network type for a given interface.
func TCPPing ¶ added in v0.12.0
TCPPing returns the duration required to establish a TCP connection to the given host. ICMP packets require root privileges, hence why we use tcp.
func TempFile ¶ added in v0.14.37
TempFile creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, and returns the resulting *os.File. If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.
func TraversesSymlink ¶ added in v0.14.19
func TraversesSymlink(filesystem fs.Filesystem, name string) error
TraversesSymlink returns an error if base and any path component of name up to and including filepath.Join(base, name) traverses a symlink. Base and name must both be clean and name must be relative to base.
Types ¶
type AtomicWriter ¶
type AtomicWriter struct {
// contains filtered or unexported fields
}
An AtomicWriter is an *os.File that writes to a temporary file in the same directory as the final path. On successful Close the file is renamed to it's final path. Any error on Write or during Close is accumulated and returned on Close, so a lazy user can ignore errors until Close.
func CreateAtomic ¶
func CreateAtomic(path string) (*AtomicWriter, error)
CreateAtomic is like os.Create, except a temporary file name is used instead of the given name. The file is created with secure (0600) permissions.
func CreateAtomicFilesystem ¶ added in v0.14.37
func CreateAtomicFilesystem(filesystem fs.Filesystem, path string) (*AtomicWriter, error)
CreateAtomicFilesystem is like os.Create, except a temporary file name is used instead of the given name. The file is created with secure (0600) permissions.
func (*AtomicWriter) Close ¶
func (w *AtomicWriter) Close() error
Close closes the temporary file and renames it to the final path. It is invalid to call Write() or Close() after Close().
type NotADirectoryError ¶ added in v0.14.19
type NotADirectoryError struct {
// contains filtered or unexported fields
}
NotADirectoryError is an error indicating an expected path is not a directory
func (NotADirectoryError) Error ¶ added in v0.14.19
func (e NotADirectoryError) Error() string
type ReplacingWriter ¶
type TraversesSymlinkError ¶ added in v0.14.19
type TraversesSymlinkError struct {
// contains filtered or unexported fields
}
TraversesSymlinkError is an error indicating symlink traversal
func (TraversesSymlinkError) Error ¶ added in v0.14.19
func (e TraversesSymlinkError) Error() string