Skip to content

Commit

Permalink
Merge pull request #144 from vim-volt/skip-copy-symlink
Browse files Browse the repository at this point in the history
cmd/build: Skip copying invalid files (e.g. symlinks)
  • Loading branch information
tyru authored Dec 24, 2017
2 parents 3d9bf92 + b4fffab commit 052b9ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
9 changes: 2 additions & 7 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
)

var BuildModeInvalidType = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice
var ErrBuildModeType = "does not allow symlink, named pipe, socket, device"

func init() {
cmdMap["build"] = &buildCmd{}
Expand Down Expand Up @@ -796,12 +795,8 @@ func (cmd *buildCmd) updateNonBareGitRepos(r *git.Repository, src, dst string, r
continue
}
if file.Mode()&BuildModeInvalidType != 0 {
abspath := filepath.Join(src, file.Name())
done <- actionReposResult{
err: errors.New(ErrBuildModeType + ": " + abspath),
repos: repos,
}
return
// Currenly skip the invalid files...
continue
}
if !created[dst] {
os.MkdirAll(dst, 0755)
Expand Down
8 changes: 4 additions & 4 deletions fileutil/copydir.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// CopyDir recursively copies a directory tree, attempting to preserve permissions.
// Source directory must exist, destination directory must *not* exist.
func CopyDir(src, dst string, buf []byte, perm os.FileMode, invalidType os.FileMode) error {
func CopyDir(src, dst string, buf []byte, perm os.FileMode, ignoreType os.FileMode) error {
if err := os.MkdirAll(dst, perm); err != nil {
return err
}
Expand All @@ -26,15 +26,15 @@ func CopyDir(src, dst string, buf []byte, perm os.FileMode, invalidType os.FileM
}

for i := range entries {
if entries[i].Mode()&invalidType != 0 {
return newInvalidType(entries[i].Name())
if entries[i].Mode()&ignoreType != 0 {
continue
}

srcPath := filepath.Join(src, entries[i].Name())
dstPath := filepath.Join(dst, entries[i].Name())

if entries[i].IsDir() {
if err = CopyDir(srcPath, dstPath, buf, entries[i].Mode(), invalidType); err != nil {
if err = CopyDir(srcPath, dstPath, buf, entries[i].Mode(), ignoreType); err != nil {
return err
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions fileutil/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// TryLinkDir recursively copies a directory tree, attempting to preserve permissions.
// Source directory must exist, destination directory must *not* exist.
func TryLinkDir(src, dst string, buf []byte, perm os.FileMode, invalidType os.FileMode) error {
func TryLinkDir(src, dst string, buf []byte, perm os.FileMode, ignoreType os.FileMode) error {
if err := os.MkdirAll(dst, perm); err != nil {
return err
}
Expand All @@ -23,15 +23,15 @@ func TryLinkDir(src, dst string, buf []byte, perm os.FileMode, invalidType os.Fi
}

for i := range entries {
if entries[i].Mode()&invalidType != 0 {
return newInvalidType(entries[i].Name())
if entries[i].Mode()&ignoreType != 0 {
continue
}

srcPath := filepath.Join(src, entries[i].Name())
dstPath := filepath.Join(dst, entries[i].Name())

if entries[i].IsDir() {
if err = TryLinkDir(srcPath, dstPath, buf, entries[i].Mode(), invalidType); err != nil {
if err = TryLinkDir(srcPath, dstPath, buf, entries[i].Mode(), ignoreType); err != nil {
return err
}
} else {
Expand Down

0 comments on commit 052b9ee

Please sign in to comment.