Skip to content

Commit

Permalink
Merge pull request #7298 from hashicorp/jbardin/GH-7273-fixup
Browse files Browse the repository at this point in the history
code: Add proper build constraints for GH-7273
  • Loading branch information
jen20 authored Jun 24, 2016
2 parents 4b1b185 + 525485c commit 8284b79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
30 changes: 10 additions & 20 deletions config/module/copy_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
)

// copyDir copies the src directory contents into dst. Both directories
Expand Down Expand Up @@ -39,13 +38,7 @@ func copyDir(dst, src string) error {
dstPath := filepath.Join(dst, path[len(src):])

// we don't want to try and copy the same file over itself.
if path == dstPath {
return nil
}

// We still might have the same file through a link, so check the
// inode if we can
if eq, err := sameInode(path, dstPath); eq {
if eq, err := sameFile(path, dstPath); eq {
return nil
} else if err != nil {
return err
Expand Down Expand Up @@ -90,31 +83,28 @@ func copyDir(dst, src string) error {
return filepath.Walk(src, walkFn)
}

// sameInode looks up the inode for paths a and b and returns if they are
// equal. On windows this will always return false.
func sameInode(a, b string) (bool, error) {
var aIno, bIno uint64
aStat, err := os.Stat(a)
// sameFile tried to determine if to paths are the same file.
// If the paths don't match, we lookup the inode on supported systems.
func sameFile(a, b string) (bool, error) {
if a == b {
return true, nil
}

aIno, err := inode(a)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
if st, ok := aStat.Sys().(*syscall.Stat_t); ok {
aIno = st.Ino
}

bStat, err := os.Stat(b)
bIno, err := inode(b)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
if st, ok := bStat.Sys().(*syscall.Stat_t); ok {
bIno = st.Ino
}

if aIno > 0 && aIno == bIno {
return true, nil
Expand Down
21 changes: 21 additions & 0 deletions config/module/inode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build !windows

package module

import (
"fmt"
"os"
"syscall"
)

// lookup the inode of a file on posix systems
func inode(path string) (uint64, error) {
stat, err := os.Stat(path)
if err != nil {
return 0, err
}
if st, ok := stat.Sys().(*syscall.Stat_t); ok {
return st.Ino, nil
}
return 0, fmt.Errorf("could not determine file inode")
}
6 changes: 6 additions & 0 deletions config/module/inode_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package module

// no syscall.Stat_t on windows, return 0 for inodes
func inode(path string) (uint64, error) {
return 0, nil
}

0 comments on commit 8284b79

Please sign in to comment.