mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 11:28:59 +00:00
d6fbfc3545
The folder already knew how to stop properly, but the fs.Walk() didn't and can potentially take a very long time. This adds context support to Walk and the underlying scanning stuff, and passes in an appropriate context from above. The stop channel in model.folder is replaced with a context for this purpose. To test I added an infiniteFS that represents a large amount of data (not actually infinite, but close) and verify that walking it is properly stopped. For that to be implemented smoothly I moved out the Walk function to it's own type, as typically the implementer of a new filesystem type might not need or want to reimplement Walk. It's somewhat tricky to test that this actually works properly on the actual sendReceiveFolder and so on, as those are started from inside the model and the filesystem isn't easily pluggable etc. Instead I've tested that part manually by adding a huge folder and verifying that pause, resume and reconfig do the right things by looking at debug output. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4117
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
|
"github.com/syncthing/syncthing/lib/scanner"
|
|
)
|
|
|
|
func main() {
|
|
log.SetFlags(0)
|
|
log.SetOutput(os.Stdout)
|
|
|
|
standardBlocks := flag.Bool("s", false, "Use standard block size")
|
|
flag.Parse()
|
|
|
|
path := flag.Arg(0)
|
|
if path == "" {
|
|
log.Fatal("Need one argument: path to check")
|
|
}
|
|
|
|
log.Println("File:")
|
|
log.Println(" ", filepath.Clean(path))
|
|
log.Println()
|
|
|
|
fi, err := os.Lstat(path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Lstat:")
|
|
log.Printf(" Size: %d bytes", fi.Size())
|
|
log.Printf(" Mode: 0%o", fi.Mode())
|
|
log.Printf(" Time: %v", fi.ModTime())
|
|
log.Printf(" %d.%09d", fi.ModTime().Unix(), fi.ModTime().Nanosecond())
|
|
log.Println()
|
|
|
|
if !fi.Mode().IsDir() && !fi.Mode().IsRegular() {
|
|
fi, err = os.Stat(path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Stat:")
|
|
log.Printf(" Size: %d bytes", fi.Size())
|
|
log.Printf(" Mode: 0%o", fi.Mode())
|
|
log.Printf(" Time: %v", fi.ModTime())
|
|
log.Printf(" %d.%09d", fi.ModTime().Unix(), fi.ModTime().Nanosecond())
|
|
log.Println()
|
|
}
|
|
|
|
if fi.Mode().IsRegular() {
|
|
log.Println("Blocks:")
|
|
|
|
fd, err := os.Open(path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
blockSize := int(fi.Size())
|
|
if *standardBlocks || blockSize < protocol.BlockSize {
|
|
blockSize = protocol.BlockSize
|
|
}
|
|
bs, err := scanner.Blocks(context.TODO(), fd, blockSize, fi.Size(), nil, true)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for _, b := range bs {
|
|
log.Println(" ", b)
|
|
}
|
|
}
|
|
}
|