osutil

package
v0.11.19 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2015 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package osutil implements utilities for native OS support.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed  = errors.New("write to closed writer")
	TempPrefix = ".syncthing.tmp."
)
View Source
var ErrNoHome = errors.New("No home directory found - set $HOME (or the platform equivalent).")

Functions

func Copy added in v0.10.21

func Copy(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 ExpandTilde added in v0.10.0

func ExpandTilde(path string) (string, error)

func GetLans added in v0.10.26

func GetLans() ([]*net.IPNet, error)

func Glob added in v0.11.2

func Glob(pattern string) (matches []string, err error)

func HideConsole added in v0.10.10

func HideConsole()

func HideFile

func HideFile(path string) error

func InWritableDir added in v0.10.0

func InWritableDir(fn func(string) error, path string) error

InWritableDir calls fn(path), while making sure that the directory containing `path` is writable for the duration of the call.

func IsWindowsExecutable added in v0.11.3

func IsWindowsExecutable(path string) bool

IsWindowsExecutable returns true if the given path has an extension that is in the list of executable extensions.

func Lstat added in v0.11.0

func Lstat(name string) (fi os.FileInfo, err error)

Lstat is like os.Lstat, except lobotomized for Android. See https://forum.syncthing.net/t/2395

func MkdirAll added in v0.11.6

func MkdirAll(path string, perm os.FileMode) error

func NativeFilename added in v0.10.7

func NativeFilename(s string) string

func NormalizedFilename added in v0.10.7

func NormalizedFilename(s string) string

func Remove added in v0.11.0

func Remove(path string) error

Remove removes the given path. On Windows, removes the read-only attribute from the target prior to deletion.

func Rename

func Rename(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 ShowFile

func ShowFile(path string) error

func TryRename added in v0.10.21

func TryRename(from, to string) error

TryRename renames a file, leaving source file intact in case of failure. Tries hard to succeed on various systems by temporarily tweaking directory permissions and removing the destination file when necessary.

Types

type AtomicWriter added in v0.11.14

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 added in v0.11.14

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 added in v0.11.14

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().

func (*AtomicWriter) Write added in v0.11.14

func (w *AtomicWriter) Write(bs []byte) (int, error)

Write is like io.Writer, but is a no-op on an already failed AtomicWriter.

type ReplacingWriter added in v0.10.3

type ReplacingWriter struct {
	Writer io.Writer
	From   byte
	To     []byte
}

func (ReplacingWriter) Write added in v0.10.3

func (w ReplacingWriter) Write(bs []byte) (int, error)

Jump to

Keyboard shortcuts

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