Merge remote-tracking branch 'origin/pr/1082'
* origin/pr/1082: Scrap IsSymlink for native support on Go 1.4
This commit is contained in:
commit
52c6869eab
@ -373,12 +373,11 @@ func (p *Puller) handleDir(file protocol.FileInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info, err := os.Lstat(realName)
|
info, err := os.Lstat(realName)
|
||||||
isLink, _ := symlinks.IsSymlink(realName)
|
|
||||||
switch {
|
switch {
|
||||||
// There is already something under that name, but it's a file/link.
|
// There is already something under that name, but it's a file/link.
|
||||||
// Most likely a file/link is getting replaced with a directory.
|
// Most likely a file/link is getting replaced with a directory.
|
||||||
// Remove the file/link and fall through to directory creation.
|
// Remove the file/link and fall through to directory creation.
|
||||||
case isLink || (err == nil && !info.IsDir()):
|
case err == nil && (!info.IsDir() || info.Mode()&os.ModeSymlink != 0):
|
||||||
err = osutil.InWritableDir(os.Remove, realName)
|
err = osutil.InWritableDir(os.Remove, realName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err)
|
||||||
@ -795,8 +794,7 @@ func (p *Puller) performFinish(state *sharedPullerState) {
|
|||||||
// If the target path is a symlink or a directory, we cannot copy
|
// If the target path is a symlink or a directory, we cannot copy
|
||||||
// over it, hence remove it before proceeding.
|
// over it, hence remove it before proceeding.
|
||||||
stat, err := os.Lstat(state.realName)
|
stat, err := os.Lstat(state.realName)
|
||||||
isLink, _ := symlinks.IsSymlink(state.realName)
|
if err == nil && (stat.IsDir() || stat.Mode()&os.ModeSymlink != 0) {
|
||||||
if isLink || (err == nil && stat.IsDir()) {
|
|
||||||
osutil.InWritableDir(os.Remove, state.realName)
|
osutil.InWritableDir(os.Remove, state.realName)
|
||||||
}
|
}
|
||||||
// Replace the original content with the new one
|
// Replace the original content with the new one
|
||||||
|
|||||||
@ -131,12 +131,9 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must perform this check, as symlinks on Windows are always
|
|
||||||
// .IsRegular or .IsDir unlike on Unix.
|
|
||||||
// Index wise symlinks are always files, regardless of what the target
|
// Index wise symlinks are always files, regardless of what the target
|
||||||
// is, because symlinks carry their target path as their content.
|
// is, because symlinks carry their target path as their content.
|
||||||
isSymlink, _ := symlinks.IsSymlink(p)
|
if info.Mode()&os.ModeSymlink != 0 {
|
||||||
if isSymlink {
|
|
||||||
var rval error
|
var rval error
|
||||||
// If the target is a directory, do NOT descend down there.
|
// If the target is a directory, do NOT descend down there.
|
||||||
// This will cause files to get tracked, and removing the symlink
|
// This will cause files to get tracked, and removing the symlink
|
||||||
@ -199,7 +196,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
|
|||||||
if w.CurrentFiler != nil {
|
if w.CurrentFiler != nil {
|
||||||
cf := w.CurrentFiler.CurrentFile(rn)
|
cf := w.CurrentFiler.CurrentFile(rn)
|
||||||
permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode()))
|
permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode()))
|
||||||
if !cf.IsDeleted() && cf.IsDirectory() && permUnchanged {
|
if !cf.IsDeleted() && cf.IsDirectory() && permUnchanged && !cf.IsSymlink() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,14 +41,6 @@ func Read(path string) (string, uint32, error) {
|
|||||||
return osutil.NormalizedFilename(path), mode, err
|
return osutil.NormalizedFilename(path), mode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSymlink(path string) (bool, error) {
|
|
||||||
lstat, err := os.Lstat(path)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return lstat.Mode()&os.ModeSymlink != 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Create(source, target string, flags uint32) error {
|
func Create(source, target string, flags uint32) error {
|
||||||
return os.Symlink(osutil.NativeFilename(target), source)
|
return os.Symlink(osutil.NativeFilename(target), source)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,8 +69,8 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isLink, err := IsSymlink(path)
|
stat, err := os.Lstat(path)
|
||||||
if err != nil || !isLink {
|
if err != nil || stat.Mode()&os.ModeSymlink == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,19 +139,6 @@ func Read(path string) (string, uint32, error) {
|
|||||||
return osutil.NormalizedFilename(data.PrintName()), flags, nil
|
return osutil.NormalizedFilename(data.PrintName()), flags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSymlink(path string) (bool, error) {
|
|
||||||
ptr, err := syscall.UTF16PtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
attr, err := syscall.GetFileAttributes(ptr)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return attr&FILE_ATTRIBUTE_REPARSE_POINT != 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Create(source, target string, flags uint32) error {
|
func Create(source, target string, flags uint32) error {
|
||||||
srcp, err := syscall.UTF16PtrFromString(source)
|
srcp, err := syscall.UTF16PtrFromString(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user