lib/scanner: Consistenlty use CreateFileInfo and remove outdated comment (#5574)

This commit is contained in:
Simon Frei 2019-03-04 13:27:33 +01:00 committed by GitHub
parent d6622b1f68
commit 0f80318ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -304,7 +304,7 @@ func (w *walker) handleItem(ctx context.Context, path string, toHashChan chan<-
switch { switch {
case info.IsSymlink(): case info.IsSymlink():
if err := w.walkSymlink(ctx, path, finishedChan); err != nil { if err := w.walkSymlink(ctx, path, info, finishedChan); err != nil {
return err return err
} }
if info.IsDir() { if info.IsDir() {
@ -411,19 +411,14 @@ func (w *walker) walkDir(ctx context.Context, relPath string, info fs.FileInfo,
// walkSymlink returns nil or an error, if the error is of the nature that // walkSymlink returns nil or an error, if the error is of the nature that
// it should stop the entire walk. // it should stop the entire walk.
func (w *walker) walkSymlink(ctx context.Context, relPath string, finishedChan chan<- ScanResult) error { func (w *walker) walkSymlink(ctx context.Context, relPath string, info fs.FileInfo, finishedChan chan<- ScanResult) error {
// Symlinks are not supported on Windows. We ignore instead of returning // Symlinks are not supported on Windows. We ignore instead of returning
// an error. // an error.
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
return nil return nil
} }
// We always rehash symlinks as they have no modtime or f, err := CreateFileInfo(info, relPath, w.Filesystem)
// permissions. We check if they point to the old target by
// checking that their existing blocks match with the blocks in
// the index.
target, err := w.Filesystem.ReadSymlink(relPath)
if err != nil { if err != nil {
w.handleError(ctx, "reading link:", relPath, err, finishedChan) w.handleError(ctx, "reading link:", relPath, err, finishedChan)
return nil return nil
@ -431,12 +426,6 @@ func (w *walker) walkSymlink(ctx context.Context, relPath string, finishedChan c
curFile, hasCurFile := w.CurrentFiler.CurrentFile(relPath) curFile, hasCurFile := w.CurrentFiler.CurrentFile(relPath)
f := protocol.FileInfo{
Name: relPath,
Type: protocol.FileInfoTypeSymlink,
NoPermissions: true, // Symlinks don't have permissions of their own
SymlinkTarget: target,
}
f = w.updateFileInfo(f, curFile) f = w.updateFileInfo(f, curFile)
if hasCurFile { if hasCurFile {
@ -613,6 +602,7 @@ func CreateFileInfo(fi fs.FileInfo, name string, filesystem fs.Filesystem) (prot
return protocol.FileInfo{}, err return protocol.FileInfo{}, err
} }
f.SymlinkTarget = target f.SymlinkTarget = target
f.NoPermissions = true // Symlinks don't have permissions of their own
return f, nil return f, nil
} }
f.Permissions = uint32(fi.Mode() & fs.ModePerm) f.Permissions = uint32(fi.Mode() & fs.ModePerm)