func unmarshalTrunc(bs []byte, truncate bool) (protocol.FileIntf, error) { if truncate { var tf protocol.FileInfoTruncated err := tf.UnmarshalXDR(bs) return tf, err } else { var tf protocol.FileInfo err := tf.UnmarshalXDR(bs) return tf, err } }
func ldbGetGlobal(db *leveldb.DB, folder, file []byte) protocol.FileInfo { k := globalKey(folder, file) snap, err := db.GetSnapshot() if err != nil { panic(err) } if debugDB { l.Debugf("created snapshot %p", snap) } defer func() { if debugDB { l.Debugf("close snapshot %p", snap) } snap.Release() }() if debugDB { l.Debugf("snap.Get %p %x", snap, k) } bs, err := snap.Get(k, nil) if err == leveldb.ErrNotFound { return protocol.FileInfo{} } if err != nil { panic(err) } var vl versionList err = vl.UnmarshalXDR(bs) if err != nil { panic(err) } if len(vl.versions) == 0 { l.Debugln(k) panic("no versions?") } k = deviceKey(folder, vl.versions[0].device, file) if debugDB { l.Debugf("snap.Get %p %x", snap, k) } bs, err = snap.Get(k, nil) if err != nil { panic(err) } var f protocol.FileInfo err = f.UnmarshalXDR(bs) if err != nil { panic(err) } return f }
func ldbGet(db *leveldb.DB, folder, device, file []byte) protocol.FileInfo { nk := deviceKey(folder, device, file) bs, err := db.Get(nk, nil) if err == leveldb.ErrNotFound { return protocol.FileInfo{} } if err != nil { panic(err) } var f protocol.FileInfo err = f.UnmarshalXDR(bs) if err != nil { panic(err) } return f }