2014-12-03 08:59:09 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// 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 http://mozilla.org/MPL/2.0/.
|
2014-12-03 08:59:09 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2015-09-22 17:38:46 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-08-06 09:29:25 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/scanner"
|
2014-12-03 08:59:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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())
|
2016-08-06 13:05:59 +00:00
|
|
|
log.Printf(" Time: %v", fi.ModTime())
|
|
|
|
log.Printf(" %d.%09d", fi.ModTime().Unix(), fi.ModTime().Nanosecond())
|
2014-12-03 08:59:09 +00:00
|
|
|
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())
|
2016-08-06 13:05:59 +00:00
|
|
|
log.Printf(" Time: %v", fi.ModTime())
|
|
|
|
log.Printf(" %d.%09d", fi.ModTime().Unix(), fi.ModTime().Nanosecond())
|
2014-12-03 08:59:09 +00:00
|
|
|
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
|
|
|
|
}
|
2017-01-23 13:50:32 +00:00
|
|
|
bs, err := scanner.Blocks(fd, blockSize, fi.Size(), nil, true)
|
2014-12-03 08:59:09 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, b := range bs {
|
|
|
|
log.Println(" ", b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|