From 3a6eeef58082bf718b7a464cf699c8ffae2761d1 Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Sun, 15 Mar 2015 22:14:44 +0900 Subject: [PATCH] Do not send group/others-writable bits from Windows. There is no user/group/others in Windows' read-only attribute, and all "w" bits are set in os.FileInfo if the file is not read-only. Do not send these group/others-writable bits to other devices in order to avoid unexpected world-writable files on other platforms. --- internal/scanner/walk.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 06906e630..08b094e86 100644 --- a/internal/scanner/walk.go +++ b/internal/scanner/walk.go @@ -30,6 +30,21 @@ import ( "golang.org/x/text/unicode/norm" ) +var maskModePerm os.FileMode + +func init() { + if runtime.GOOS == "windows" { + // There is no user/group/others in Windows' read-only + // attribute, and all "w" bits are set in os.FileInfo + // if the file is not read-only. Do not send these + // group/others-writable bits to other devices in order to + // avoid unexpected world-writable files on other platforms. + maskModePerm = os.ModePerm & 0755 + } else { + maskModePerm = os.ModePerm + } +} + type Walker struct { // Dir is the base directory for the walk Dir string @@ -239,7 +254,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun if w.IgnorePerms { flags |= protocol.FlagNoPermBits | 0777 } else { - flags |= uint32(info.Mode() & os.ModePerm) + flags |= uint32(info.Mode() & maskModePerm) } f := protocol.FileInfo{ Name: rn, @@ -277,7 +292,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun } } - var flags = uint32(info.Mode() & os.ModePerm) + var flags = uint32(info.Mode() & maskModePerm) if w.IgnorePerms { flags = protocol.FlagNoPermBits | 0666 }