From 101d5be2c51043d88ed90151111965861c90ddf2 Mon Sep 17 00:00:00 2001 From: Pacien Date: Tue, 16 Jul 2013 12:38:59 +0200 Subject: Close #1: no more "*&"! --- fcmd.go | 63 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/fcmd.go b/fcmd.go index 2193f71..e057587 100644 --- a/fcmd.go +++ b/fcmd.go @@ -38,17 +38,14 @@ var DefaultPerm os.FileMode = 0750 // u=rwx, g=r-x, o=--- // Checks if the target exists. func IsExist(target string) bool { - _, err := os.Stat(*&target) - if os.IsNotExist(*&err) { - return false - } - return true + _, err := os.Stat(target) + return os.IsNotExist(err) } // Checks if the target is a directory. // Returns false if the target is unreachable. func IsDir(target string) bool { - stat, err := os.Stat(*&target) + stat, err := os.Stat(target) if err != nil { return false } @@ -57,13 +54,13 @@ func IsDir(target string) bool { // Checks lexically if the target is hidden (only for Unix based OS). func IsHidden(target string) bool { - return strings.HasPrefix(*&target, ".") + return strings.HasPrefix(target, ".") } // 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) + directory, err := ioutil.ReadDir(target) if err != nil { return } @@ -72,9 +69,9 @@ func Ls(target string) (dirs, files []string) { continue } if element.IsDir() { - dirs = append(*&dirs, element.Name()) + dirs = append(dirs, element.Name()) } else { - files = append(*&files, element.Name()) + files = append(files, element.Name()) } } return @@ -84,21 +81,21 @@ func Ls(target string) (dirs, files []string) { // 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) + dirList, fileList := Ls(root) for _, file := range fileList { - files = append(*&files, *&file) + files = append(files, file) } for _, dir := range dirList { - subRoot := path.Join(*&root, *&dir) - dirs = append(dirs, *&subRoot) - subDirs, subFiles := Explore(*&subRoot) + subRoot := path.Join(root, dir) + dirs = append(dirs, subRoot) + subDirs, subFiles := Explore(subRoot) for _, subFile := range subFiles { - files = append(*&files, *&subFile) + files = append(files, subFile) } for _, subDir := range subDirs { - dirs = append(*&dirs, *&subDir) + dirs = append(dirs, subDir) } } return @@ -108,26 +105,26 @@ func Explore(root string) (dirs, files []string) { // 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) + sourceFile, err := os.Open(source) if err != nil { return err } defer sourceFile.Close() - dir, _ := path.Split(*&target) + dir, _ := path.Split(target) - err = os.MkdirAll(*&dir, DefaultPerm) + err = os.MkdirAll(dir, DefaultPerm) if err != nil { return err } - targetFile, err := os.Create(*&target) + targetFile, err := os.Create(target) if err != nil { return err } defer targetFile.Close() - _, err = io.Copy(*&targetFile, *&sourceFile) + _, err = io.Copy(targetFile, sourceFile) return err } @@ -135,56 +132,56 @@ func Cp(source, target string) error { // 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) + 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. func Lns(source, target string) error { - return os.Symlink(*&source, *&target) + return os.Symlink(source, target) } // Returns the destination of the given symbolic link. func Lnl(target string) (string, error) { - return os.Readlink(*&target) + return os.Readlink(target) } // 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) + 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. func Rm(target string) error { - return os.RemoveAll(*&target) + return os.RemoveAll(target) } // Changes the current working directory to the target directory. func Cd(target string) error { - return os.Chdir(*&target) + 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. func Chmod(target string, mode os.FileMode) error { - return os.Chmod(*&target, *&mode) + 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. func Chown(target string, uid, gid int) error { - return os.Chown(*&target, *&uid, *&gid) + return os.Chown(target, uid, gid) } // 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) + return os.Chtimes(target, atime, mtime) } -- cgit v1.2.3