Documentation ¶
Overview ¶
Package osutil implements utilities for native OS support.
Index ¶
- Variables
- func Copy(from, to string) (err error)
- func DiskFreeBytes(path string) (free int64, err error)
- func DiskFreePercentage(path string) (freePct float64, err error)
- func ExpandTilde(path string) (string, error)
- func GetLans() ([]*net.IPNet, error)
- func GetLatencyForURL(addr string) (time.Duration, error)
- func Glob(pattern string) (matches []string, err error)
- func HideConsole()
- func HideFile(path string) error
- func InWritableDir(fn func(string) error, path string) error
- func IsWindowsExecutable(path string) bool
- func Lstat(name string) (fi os.FileInfo, err error)
- func MaximizeOpenFileLimit() (int, error)
- func MkdirAll(path string, perm os.FileMode) error
- func NativeFilename(s string) string
- func NormalizedFilename(s string) string
- func Remove(path string) error
- func Rename(from, to string) error
- func SetTCPOptions(conn *net.TCPConn) error
- func ShowFile(path string) error
- func TCPPing(address string) (time.Duration, error)
- func TryRename(from, to string) error
- type AtomicWriter
- type ReplacingWriter
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("write to closed writer") TempPrefix = ".syncthing.tmp." )
var ErrNoHome = errors.New("No home directory found - set $HOME (or the platform equivalent).")
Functions ¶
func Copy ¶
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 DiskFreeBytes ¶
func DiskFreePercentage ¶
func ExpandTilde ¶
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 Lstat ¶
Lstat is like os.Lstat, except lobotomized for Android. See https://forum.syncthing.net/t/2395
func MaximizeOpenFileLimit ¶
MaximizeOpenFileLimit tries to set the resoure 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 was could not be changed.
func NativeFilename ¶
func NormalizedFilename ¶
func Remove ¶
Remove removes the given path. On Windows, removes the read-only attribute from the target prior to deletion.
func Rename ¶
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 SetTCPOptions ¶ added in v0.12.0
SetTCPOptions sets syncthings default TCP options on a TCP connection
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 successfull 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, mode os.FileMode) (*AtomicWriter, error)
CreateAtomic is like os.Create with a FileMode, except a temporary file name is used instead of the given name.
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().