summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-03-06 15:37:15 +0100
committerGitHub <noreply@github.com>2023-03-06 15:37:15 +0100
commitab8e6a82aba9eef49599fe99fe00abfceb86055d (patch)
tree8a7df3e61523d3d3309bdedacde5b79023cb606a
parent3cdcb7dd72bcf8f23d1d5227f3bd7b5cc4138576 (diff)
lib/api: Expose `blocksHash` in file info (#8810)
This adds the BlocksHash field from the FileInfo to our API output. It can be useful for debugging, or for external tools. I'm intentionally leaving it as an opaque base64 string because no meaning should be derived from it: it's just a string.
-rw-r--r--lib/api/api.go1
-rw-r--r--lib/db/structs.go4
-rw-r--r--lib/protocol/bep_extensions.go5
3 files changed, 10 insertions, 0 deletions
diff --git a/lib/api/api.go b/lib/api/api.go
index 456123fdc2..6f9451dcc5 100644
--- a/lib/api/api.go
+++ b/lib/api/api.go
@@ -1828,6 +1828,7 @@ func fileIntfJSONMap(f protocol.FileIntf) map[string]interface{} {
"localFlags": f.FileLocalFlags(),
"platform": f.PlatformData(),
"inodeChange": f.InodeChangeTime(),
+ "blocksHash": f.FileBlocksHash(),
}
if f.HasPermissionBits() {
out["permissions"] = fmt.Sprintf("%#o", f.FilePermissions())
diff --git a/lib/db/structs.go b/lib/db/structs.go
index daa514fab7..8c3c1f39a4 100644
--- a/lib/db/structs.go
+++ b/lib/db/structs.go
@@ -133,6 +133,10 @@ func (f FileInfoTruncated) InodeChangeTime() time.Time {
return time.Unix(0, f.InodeChangeNs)
}
+func (f FileInfoTruncated) FileBlocksHash() []byte {
+ return f.BlocksHash
+}
+
func (f FileInfoTruncated) ConvertToIgnoredFileInfo() protocol.FileInfo {
file := f.copyToFileInfo()
file.SetIgnored()
diff --git a/lib/protocol/bep_extensions.go b/lib/protocol/bep_extensions.go
index 2290f2cce9..4ee23adc5a 100644
--- a/lib/protocol/bep_extensions.go
+++ b/lib/protocol/bep_extensions.go
@@ -46,6 +46,7 @@ type FileIntf interface {
ModTime() time.Time
PlatformData() PlatformData
InodeChangeTime() time.Time
+ FileBlocksHash() []byte
}
func (Hello) Magic() uint32 {
@@ -170,6 +171,10 @@ func (f FileInfo) InodeChangeTime() time.Time {
return time.Unix(0, f.InodeChangeNs)
}
+func (f FileInfo) FileBlocksHash() []byte {
+ return f.BlocksHash
+}
+
// WinsConflict returns true if "f" is the one to choose when it is in
// conflict with "other".
func WinsConflict(f, other FileIntf) bool {