mirror of https://github.com/schollz/croc.git
Merge pull request #361 from tdussa/BrokenSymlink
Transfer symlinks without touching their targets.
This commit is contained in:
commit
828de41d6c
|
@ -324,7 +324,7 @@ func getPaths(fnames []string) (paths []string, haveFolder bool, err error) {
|
||||||
haveFolder = false
|
haveFolder = false
|
||||||
paths = []string{}
|
paths = []string{}
|
||||||
for _, fname := range fnames {
|
for _, fname := range fnames {
|
||||||
stat, errStat := os.Stat(fname)
|
stat, errStat := os.Lstat(fname)
|
||||||
if errStat != nil {
|
if errStat != nil {
|
||||||
err = errStat
|
err = errStat
|
||||||
return
|
return
|
||||||
|
|
|
@ -41,8 +41,23 @@ func GetInput(prompt string) string {
|
||||||
return strings.TrimSpace(text)
|
return strings.TrimSpace(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HashFile returns the hash of a file or, in case of a symlink, the
|
||||||
|
// SHA256 hash of its target
|
||||||
// HashFile returns the hash of a file
|
// HashFile returns the hash of a file
|
||||||
func HashFile(fname string) (hash256 []byte, err error) {
|
func HashFile(fname string) (hash256 []byte, err error) {
|
||||||
|
var fstats os.FileInfo
|
||||||
|
fstats, err = os.Lstat(fname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if fstats.Mode()&os.ModeSymlink != 0 {
|
||||||
|
var target string
|
||||||
|
target, err = os.Readlink(fname)
|
||||||
|
return []byte(SHA256(target)), nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return IMOHashFile(fname)
|
return IMOHashFile(fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue