From f4e9eeb15ab84db1e29cfffd6124a18833ae8e28 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 19 Mar 2018 09:46:31 -0700 Subject: [PATCH] Modified fs util functions --- pkg/commands/copy.go | 3 --- pkg/util/fs_util.go | 15 +++------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/commands/copy.go b/pkg/commands/copy.go index cc6a21721..cbdba436b 100644 --- a/pkg/commands/copy.go +++ b/pkg/commands/copy.go @@ -82,9 +82,6 @@ func (c *CopyCommand) ExecuteCommand(config *manifest.Schema2Config) error { // FilesToSnapshot should return an empty array if still nil; no files were changed func (c *CopyCommand) FilesToSnapshot() []string { - if c.snapshotFiles == nil { - return []string{} - } return c.snapshotFiles } diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 036414f9e..386ebe19c 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -23,6 +23,7 @@ import ( "github.com/containers/image/docker" "github.com/sirupsen/logrus" "io" + "io/ioutil" "os" "path/filepath" "strings" @@ -120,7 +121,7 @@ func RelativeFiles(fp string, root string) ([]string, error) { // FilepathExists returns true if the path exists func FilepathExists(path string) bool { _, err := os.Stat(path) - return (err == nil) + return !os.IsNotExist(err) } // CreateFile creates a file at path with contents specified @@ -133,15 +134,5 @@ func CreateFile(path string, contents []byte, perm os.FileMode) error { return err } } - - f, err := os.Create(path) - defer f.Close() - if err != nil { - return err - } - _, err = f.Write(contents) - if err != nil { - return err - } - return f.Chmod(perm) + return ioutil.WriteFile(path, contents, perm) }