Documentation ¶
Overview ¶
Package file handles common operations in files.
The editing of files is very important in the shell scripting to working with the configuration files. There are a great number of functions related to it, avoiding to have to use an external command to get the same result and with the advantage of that it creates automatically a backup before of editing.
NewEdit creates a new struct, edit, which has a variable, CommentChar, with a value by default, '#'. That value is the character used in comments.
Index ¶
- Constants
- func Append(filename string, b []byte) error
- func AppendString(filename, s string) error
- func Backup(filename string) error
- func Comment(filename, reLine string) error
- func CommentM(filename string, reLine []string) error
- func CommentOut(filename, reLine string) error
- func CommentOutM(filename string, reLine []string) error
- func Contain(filename string, b []byte) (bool, error)
- func ContainString(filename, s string) (bool, error)
- func Copy(source, dest string) (err error)
- func CopytoTemp(source, prefix string) (tmpFile string, err error)
- func Create(filename string, b []byte) (err error)
- func CreateString(filename, s string) error
- func GroupHas(name string, p ...perm) (bool, error)
- func IsDir(name string) (bool, error)
- func IsFile(name string) (bool, error)
- func NewEdit(filename string) (*edit, error)
- func NewInfo(name string) (*info, error)
- func OthersHave(name string, p ...perm) (bool, error)
- func Overwrite(filename string, b []byte) (err error)
- func OverwriteString(filename, s string) error
- func OwnerHas(name string, p ...perm) (bool, error)
- func Replace(filename string, r []Replacer) error
- func ReplaceAtLine(filename string, r []ReplacerAtLine) error
- func ReplaceAtLineN(filename string, r []ReplacerAtLine, n int) error
- func ReplaceN(filename string, r []Replacer, n int) error
- type Replacer
- type ReplacerAtLine
Constants ¶
const ( R perm // read W // write X // execute )
permissions
const PREFIX_TEMP = "test-" // Prefix to add to temporary files.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append writes len(b) bytes at the end of the named file. It returns an error, if any. The file is backed up.
func AppendString ¶
AppendString is like Append, but writes the contents of string s rather than an array of bytes.
func Backup ¶
Backup creates a backup of the named file.
The schema used for the new name is: {name}\+[1-9]~
name: The original file name. + : Character used to separate the file name from rest. number: A number from 1 to 9, using rotation. ~ : To indicate that it is a backup, just like it is used in Unix systems.
func Comment ¶
Comment inserts the comment character in lines that mach the regular expression in reLine, in the named file.
func CommentM ¶
CommentM inserts the comment character in lines that mach any regular expression in reLine, in the named file.
func CommentOut ¶
CommentOut removes the comment character of lines that mach the regular expression in reLine, in the named file.
func CommentOutM ¶
CommentOutM removes the comment character of lines that mach any regular expression in reLine, in the named file.
func Contain ¶
Contain returns whether the named file contains the byte slice b. The return value is a boolean.
func ContainString ¶
ContainString returns whether the named file contains the string s. The return value is a boolean.
func CopytoTemp ¶
CopytoTemp creates a temporary file from the source file into the default directory for temporary files (see os.TempDir), whose name begins with prefix. If prefix is the empty string, uses the default value PREFIX_TEMP. Returns the temporary file name.
func CreateString ¶
CreateString is like Create, but writes the contents of string s rather than an array of bytes.
func OthersHave ¶
OthersHave reports whether the named file have all given permissions for the others.
func Overwrite ¶
Overwrite truncates the named file to zero and writes len(b) bytes. It returns an error, if any.
func OverwriteString ¶
OverwriteString is like Overwrite, but writes the contents of string s rather than an array of bytes.
func ReplaceAtLine ¶
func ReplaceAtLine(filename string, r []ReplacerAtLine) error
ReplaceAtLine replaces all regular expressions mathed in r for the named file, if the line is matched at the first.
func ReplaceAtLineN ¶
func ReplaceAtLineN(filename string, r []ReplacerAtLine, n int) error
ReplaceAtLineN replaces a number of regular expressions mathed in r for the named file, if the line is matched at the first.
Types ¶
type ReplacerAtLine ¶
type ReplacerAtLine struct {
Line, Search, Replace string
}