mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 14:58:26 +00:00
Expose flags, options in Index{,Update}
This commit is contained in:
parent
1a59a5478f
commit
1cb5875b20
@ -25,10 +25,10 @@ func newTestModel() *TestModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
||||||
|
@ -12,18 +12,18 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
for i := range files {
|
for i := range files {
|
||||||
files[i].Name = norm.NFD.String(files[i].Name)
|
files[i].Name = norm.NFD.String(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.Index(deviceID, folder, files)
|
m.next.Index(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
for i := range files {
|
for i := range files {
|
||||||
files[i].Name = norm.NFD.String(files[i].Name)
|
files[i].Name = norm.NFD.String(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.IndexUpdate(deviceID, folder, files)
|
m.next.IndexUpdate(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
||||||
|
@ -10,12 +10,12 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
m.next.Index(deviceID, folder, files)
|
m.next.Index(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
m.next.IndexUpdate(deviceID, folder, files)
|
m.next.IndexUpdate(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
||||||
|
@ -24,7 +24,7 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
for i, f := range files {
|
for i, f := range files {
|
||||||
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
||||||
if f.IsDeleted() {
|
if f.IsDeleted() {
|
||||||
@ -37,10 +37,10 @@ func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
|||||||
}
|
}
|
||||||
files[i].Name = filepath.FromSlash(f.Name)
|
files[i].Name = filepath.FromSlash(f.Name)
|
||||||
}
|
}
|
||||||
m.next.Index(deviceID, folder, files)
|
m.next.Index(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
|
||||||
for i, f := range files {
|
for i, f := range files {
|
||||||
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
||||||
if f.IsDeleted() {
|
if f.IsDeleted() {
|
||||||
@ -53,7 +53,7 @@ func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileI
|
|||||||
}
|
}
|
||||||
files[i].Name = filepath.FromSlash(files[i].Name)
|
files[i].Name = filepath.FromSlash(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.IndexUpdate(deviceID, folder, files)
|
m.next.IndexUpdate(deviceID, folder, files, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
||||||
|
32
protocol.go
32
protocol.go
@ -66,9 +66,9 @@ type pongMessage struct{ EmptyMessage }
|
|||||||
|
|
||||||
type Model interface {
|
type Model interface {
|
||||||
// An index was received from the peer device
|
// An index was received from the peer device
|
||||||
Index(deviceID DeviceID, folder string, files []FileInfo)
|
Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option)
|
||||||
// An index update was received from the peer device
|
// An index update was received from the peer device
|
||||||
IndexUpdate(deviceID DeviceID, folder string, files []FileInfo)
|
IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option)
|
||||||
// A request was made by the peer device
|
// A request was made by the peer device
|
||||||
Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error)
|
Request(deviceID DeviceID, folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error)
|
||||||
// A cluster configuration message was received
|
// A cluster configuration message was received
|
||||||
@ -80,8 +80,8 @@ type Model interface {
|
|||||||
type Connection interface {
|
type Connection interface {
|
||||||
ID() DeviceID
|
ID() DeviceID
|
||||||
Name() string
|
Name() string
|
||||||
Index(folder string, files []FileInfo) error
|
Index(folder string, files []FileInfo, flags uint32, options []Option) error
|
||||||
IndexUpdate(folder string, files []FileInfo) error
|
IndexUpdate(folder string, files []FileInfo, flags uint32, options []Option) error
|
||||||
Request(folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error)
|
Request(folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error)
|
||||||
ClusterConfig(config ClusterConfigMessage)
|
ClusterConfig(config ClusterConfigMessage)
|
||||||
Statistics() Statistics
|
Statistics() Statistics
|
||||||
@ -169,7 +169,7 @@ func (c *rawConnection) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Index writes the list of file information to the connected peer device
|
// Index writes the list of file information to the connected peer device
|
||||||
func (c *rawConnection) Index(folder string, idx []FileInfo) error {
|
func (c *rawConnection) Index(folder string, idx []FileInfo, flags uint32, options []Option) error {
|
||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
@ -177,15 +177,17 @@ func (c *rawConnection) Index(folder string, idx []FileInfo) error {
|
|||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
c.send(-1, messageTypeIndex, IndexMessage{
|
c.send(-1, messageTypeIndex, IndexMessage{
|
||||||
Folder: folder,
|
Folder: folder,
|
||||||
Files: idx,
|
Files: idx,
|
||||||
|
Flags: flags,
|
||||||
|
Options: options,
|
||||||
})
|
})
|
||||||
c.idxMut.Unlock()
|
c.idxMut.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexUpdate writes the list of file information to the connected peer device as an update
|
// IndexUpdate writes the list of file information to the connected peer device as an update
|
||||||
func (c *rawConnection) IndexUpdate(folder string, idx []FileInfo) error {
|
func (c *rawConnection) IndexUpdate(folder string, idx []FileInfo, flags uint32, options []Option) error {
|
||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
@ -193,8 +195,10 @@ func (c *rawConnection) IndexUpdate(folder string, idx []FileInfo) error {
|
|||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
c.send(-1, messageTypeIndexUpdate, IndexMessage{
|
c.send(-1, messageTypeIndexUpdate, IndexMessage{
|
||||||
Folder: folder,
|
Folder: folder,
|
||||||
Files: idx,
|
Files: idx,
|
||||||
|
Flags: flags,
|
||||||
|
Options: options,
|
||||||
})
|
})
|
||||||
c.idxMut.Unlock()
|
c.idxMut.Unlock()
|
||||||
return nil
|
return nil
|
||||||
@ -463,16 +467,16 @@ func (c *rawConnection) readMessage() (hdr header, msg encodable, err error) {
|
|||||||
|
|
||||||
func (c *rawConnection) handleIndex(im IndexMessage) {
|
func (c *rawConnection) handleIndex(im IndexMessage) {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("Index(%v, %v, %d files)", c.id, im.Folder, len(im.Files))
|
l.Debugf("Index(%v, %v, %d file, flags %x, opts: %s)", c.id, im.Folder, len(im.Files), im.Flags, im.Options)
|
||||||
}
|
}
|
||||||
c.receiver.Index(c.id, im.Folder, filterIndexMessageFiles(im.Files))
|
c.receiver.Index(c.id, im.Folder, filterIndexMessageFiles(im.Files), im.Flags, im.Options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) handleIndexUpdate(im IndexMessage) {
|
func (c *rawConnection) handleIndexUpdate(im IndexMessage) {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("queueing IndexUpdate(%v, %v, %d files)", c.id, im.Folder, len(im.Files))
|
l.Debugf("queueing IndexUpdate(%v, %v, %d files, flags %x, opts: %s)", c.id, im.Folder, len(im.Files), im.Flags, im.Options)
|
||||||
}
|
}
|
||||||
c.receiver.IndexUpdate(c.id, im.Folder, filterIndexMessageFiles(im.Files))
|
c.receiver.IndexUpdate(c.id, im.Folder, filterIndexMessageFiles(im.Files), im.Flags, im.Options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterIndexMessageFiles(fs []FileInfo) []FileInfo {
|
func filterIndexMessageFiles(fs []FileInfo) []FileInfo {
|
||||||
|
@ -229,8 +229,8 @@ func TestClose(t *testing.T) {
|
|||||||
t.Error("Ping should not return true")
|
t.Error("Ping should not return true")
|
||||||
}
|
}
|
||||||
|
|
||||||
c0.Index("default", nil)
|
c0.Index("default", nil, 0, nil)
|
||||||
c0.Index("default", nil)
|
c0.Index("default", nil, 0, nil)
|
||||||
|
|
||||||
if _, err := c0.Request("default", "foo", 0, 0, nil, 0, nil); err == nil {
|
if _, err := c0.Request("default", "foo", 0, 0, nil, 0, nil); err == nil {
|
||||||
t.Error("Request should return an error")
|
t.Error("Request should return an error")
|
||||||
|
@ -20,7 +20,7 @@ func (c wireFormatConnection) Name() string {
|
|||||||
return c.next.Name()
|
return c.next.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) Index(folder string, fs []FileInfo) error {
|
func (c wireFormatConnection) Index(folder string, fs []FileInfo, flags uint32, options []Option) error {
|
||||||
var myFs = make([]FileInfo, len(fs))
|
var myFs = make([]FileInfo, len(fs))
|
||||||
copy(myFs, fs)
|
copy(myFs, fs)
|
||||||
|
|
||||||
@ -28,10 +28,10 @@ func (c wireFormatConnection) Index(folder string, fs []FileInfo) error {
|
|||||||
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.next.Index(folder, myFs)
|
return c.next.Index(folder, myFs, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) IndexUpdate(folder string, fs []FileInfo) error {
|
func (c wireFormatConnection) IndexUpdate(folder string, fs []FileInfo, flags uint32, options []Option) error {
|
||||||
var myFs = make([]FileInfo, len(fs))
|
var myFs = make([]FileInfo, len(fs))
|
||||||
copy(myFs, fs)
|
copy(myFs, fs)
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (c wireFormatConnection) IndexUpdate(folder string, fs []FileInfo) error {
|
|||||||
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.next.IndexUpdate(folder, myFs)
|
return c.next.IndexUpdate(folder, myFs, flags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) Request(folder, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
func (c wireFormatConnection) Request(folder, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user