From c002ee50a9852fc52bae09f344031f28a7b9ef7f Mon Sep 17 00:00:00 2001 From: Pacien Date: Sun, 30 Jun 2013 23:10:17 +0200 Subject: Make DefaultPerm editable and add dots to comments --- fcmd.go | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/fcmd.go b/fcmd.go index 575934a..83b35a9 100644 --- a/fcmd.go +++ b/fcmd.go @@ -9,9 +9,9 @@ import ( "time" ) -const defaultPerm os.FileMode = 0750 // u=rwx, g=r-x, o=--- +var DefaultPerm os.FileMode = 0750 // u=rwx, g=r-x, o=--- -// Checks if the target exists +// Checks if the target exists. func IsExist(target string) bool { _, err := os.Stat(*&target) if os.IsNotExist(*&err) { @@ -20,8 +20,8 @@ func IsExist(target string) bool { return true } -// Checks if the target is a directory -// Returns false if the target is unreachable +// Checks if the target is a directory. +// Returns false if the target is unreachable. func IsDir(target string) bool { stat, err := os.Stat(*&target) if err != nil { @@ -30,13 +30,13 @@ func IsDir(target string) bool { return stat.IsDir() } -// Checks lexically if the target is hidden (only for Unix based OS) +// Checks lexically if the target is hidden (only for Unix based OS). func IsHidden(target string) bool { return strings.HasPrefix(*&target, ".") } -// Lists separately the names of directories and files inside the target directory -// Hidden files and directories are not listed +// Lists separately the names of directories and files inside the target directory. +// Hidden files and directories are not listed. func Ls(target string) (dirs, files []string) { directory, err := ioutil.ReadDir(*&target) if err != nil { @@ -55,9 +55,9 @@ func Ls(target string) (dirs, files []string) { return } -// Lists separately the paths of directories and files inside the root directory and inside all sub directories -// Returned paths are relative to the given root directory -// Hidden files and directories are not listed +// Lists separately the paths of directories and files inside the root directory and inside all sub directories. +// Returned paths are relative to the given root directory. +// Hidden files and directories are not listed. func Explore(root string) (dirs, files []string) { dirList, fileList := Ls(*&root) @@ -79,9 +79,9 @@ func Explore(root string) (dirs, files []string) { return } -// Copies the source file to a target -// A nonexistent target file is created, otherwise it is truncated -// Parent directories are automatically created if they do not exist +// Copies the source file to a target. +// A nonexistent target file is created, otherwise it is truncated. +// Parent directories are automatically created if they do not exist. func Cp(source, target string) error { sourceFile, err := os.Open(*&source) if err != nil { @@ -91,7 +91,7 @@ func Cp(source, target string) error { dir, _ := path.Split(*&target) - err = os.MkdirAll(*&dir, defaultPerm) + err = os.MkdirAll(*&dir, DefaultPerm) if err != nil { return err } @@ -106,60 +106,60 @@ func Cp(source, target string) error { return err } -// Writes data to the target file -// A nonexistent target file is created, otherwise it is truncated -// Parent directories are automatically created if they do not exist +// Writes data to the target file. +// A nonexistent target file is created, otherwise it is truncated. +// Parent directories are automatically created if they do not exist. func WriteFile(target string, data []byte) error { dir, _ := path.Split(*&target) - err := os.MkdirAll(*&dir, defaultPerm) + err := os.MkdirAll(*&dir, DefaultPerm) if err != nil { return err } - err = ioutil.WriteFile(*&target, *&data, defaultPerm) + err = ioutil.WriteFile(*&target, *&data, DefaultPerm) return err } -// Creates a symbolic link to given source at the target path +// Creates a symbolic link to given source at the target path. func Lns(source, target string) error { return os.Symlink(*&source, *&target) } -// Returns the destination of the given symbolic link +// Returns the destination of the given symbolic link. func Lnl(target string) (string, error) { return os.Readlink(*&target) } -// Renames or moves the source file or directory to the target name or path +// Renames or moves the source file or directory to the target name or path. func Mv(source, target string) error { return os.Rename(*&source, *&target) } -// Removes the target file or the target directory and all files it contains -// No error is returned is the target does not exist +// Removes the target file or the target directory and all files it contains. +// No error is returned is the target does not exist. func Rm(target string) error { return os.RemoveAll(*&target) } -// Changes the current working directory to the target directory +// Changes the current working directory to the target directory. func Cd(target string) error { return os.Chdir(*&target) } -// Changes the mode of the target file to the given mode -// If the target is a symbolic link, it changes the mode of the link's target +// Changes the mode of the target file to the given mode. +// If the target is a symbolic link, it changes the mode of the link's target. func Chmod(target string, mode os.FileMode) error { return os.Chmod(*&target, *&mode) } -// Changes the numeric uid and gid of the target -// If the target is a symbolic link, it changes the uid and gid of the link's target +// Changes the numeric uid and gid of the target. +// If the target is a symbolic link, it changes the uid and gid of the link's target. func Chown(target string, uid, gid int) error { return os.Chown(*&target, *&uid, *&gid) } -// Changes the access and modification times of the target +// Changes the access and modification times of the target. func Chtimes(target string, atime time.Time, mtime time.Time) error { return os.Chtimes(*&target, *&atime, *&mtime) } -- cgit v1.2.3