X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Ffiles.go;h=e0a2221009deda9824aa38419fec6ffc1decc0f0;hp=3e3c7ec18357e8a01e21e22906e6a5e79cb8257f;hb=6a40d84afc959f404f243b1c00ab95dc9dd9c721;hpb=ddd21f01f764a4ff61204d8e9d0ef8421ebf685c diff --git a/cmd/safcm-remote/sync/files.go b/cmd/safcm-remote/sync/files.go index 3e3c7ec..e0a2221 100644 --- a/cmd/safcm-remote/sync/files.go +++ b/cmd/safcm-remote/sync/files.go @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// +build !windows + package sync import ( @@ -113,7 +115,7 @@ reopen: oldFh, err := OpenFileNoFollow(file.Path) if err != nil { err := err.(*fs.PathError) - if err.Err == syscall.ELOOP { + if err.Err == syscall.ELOOP || err.Err == syscall.EMLINK { // Check if ELOOP was caused not by O_NOFOLLOW but by // too many nested symlinks before the final path // component. @@ -149,6 +151,15 @@ reopen: if !change.Created { // Compare permissions change.Old.Mode = oldStat.Mode() + if change.Old.Mode.Type() == fs.ModeSymlink { + // Some BSD systems permit changing permissions of + // symlinks but ignore them on traversal. To keep it + // simple we don't support that and always use 0777 + // for symlink permissions (the value on GNU/Linux). + // + // TODO: Add proper support for symlinks on BSD + change.Old.Mode |= 0777 + } if change.Old.Mode != file.Mode { if change.Old.Mode.Type() != file.Mode.Type() { changeType = true @@ -258,7 +269,7 @@ reopen: } } - // Directory: create new directory (also type change to directory) + // Directory: create new directory, also type change to directory if file.Mode.IsDir() && (change.Created || changeType) { debugf("creating directory") err := os.Mkdir(file.Path, 0700) @@ -364,7 +375,7 @@ reopen: os.Remove(tmpPath) return err } - // Permissions are irrelevant for symlinks + // Permissions are irrelevant for symlinks (on most systems) default: panic(fmt.Sprintf("invalid file type %s", file.Mode)) @@ -443,13 +454,16 @@ func diffData(oldData []byte, newData []byte) (string, error) { oldBin := !strings.HasPrefix(http.DetectContentType(oldData), "text/") newBin := !strings.HasPrefix(http.DetectContentType(newData), "text/") if oldBin && newBin { - return "Binary files differ, cannot show diff", nil + return fmt.Sprintf("Binary files differ (%d -> %d bytes), "+ + "cannot show diff", len(oldData), len(newData)), nil } if oldBin { - oldData = []byte("\n") + oldData = []byte(fmt.Sprintf("\n", + len(oldData))) } if newBin { - newData = []byte("\n") + newData = []byte(fmt.Sprintf("\n", + len(newData))) } // TODO: difflib shows empty context lines at the end of the file