Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions kernel/fileutils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const (
)

type Fileutils interface {

// Default is false. If is set to true symbolic links are copied
IgnoreSymlink(ok bool)
/*
Copy copies a source file to a destination file. File contents are copied. File mode and permissions
(as described in http://golang.org/pkg/os/#FileMode) are copied.
Expand All @@ -63,7 +64,7 @@ type Fileutils interface {
/*
Tests the existence of a file or directory at a given path. Returns true if and only if the file or
directory exists.
*/
*/
Exists(path string) bool

/*
Expand All @@ -74,12 +75,16 @@ type Fileutils interface {
}

type futils struct {
ignoreSymlink bool
}

func New() Fileutils {
return &futils{}
}

func (f *futils) IgnoreSymlink(ok bool) {
f.ignoreSymlink = true
}
func (f *futils) Copy(destPath string, srcPath string) gerror.Gerror {
if glog.V(1) {
glog.Infof("Copy(%q, %q)", destPath, srcPath)
Expand All @@ -96,7 +101,7 @@ func (f *futils) doCopy(destPath string, srcPath string, topSrcPath string) gerr
return gerr
}

if srcMode&os.ModeSymlink == os.ModeSymlink {
if srcMode&os.ModeSymlink == os.ModeSymlink && f.ignoreSymlink == false {
return f.copySymlink(destPath, srcPath, topSrcPath)
} else if srcMode.IsDir() {
return f.copyDir(destPath, srcPath, topSrcPath)
Expand Down Expand Up @@ -132,7 +137,7 @@ func (f *futils) copyDir(destination string, source string, topSource string) ge
return nil
}

func getNames(dirPath string) (names [] string, gerr gerror.Gerror) {
func getNames(dirPath string) (names []string, gerr gerror.Gerror) {
src, err := os.Open(dirPath)
if err != nil {
return names, gerror.NewFromError(ErrOpeningSourceDir, err)
Expand Down Expand Up @@ -249,7 +254,7 @@ func (f *futils) copySymlink(destLinkPath string, srcLinkPath string, topSrcPath
return nil
}

func (f * futils) Exists(path string) bool {
func (f *futils) Exists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
Expand Down