Add folder label in addition to ID (fixes #966)
An auto generated ID is suggested on folder creation to reduce conflicts with folders created on other devices.
This commit is contained in:
committed by
Jakob Borg
parent
1875f7287e
commit
16c3d39fd2
File diff suppressed because one or more lines are too long
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
type FolderConfiguration struct {
|
||||
ID string `xml:"id,attr" json:"id"`
|
||||
Label string `xml:"label,attr" json:"label"`
|
||||
RawPath string `xml:"path,attr" json:"path"`
|
||||
Devices []FolderDeviceConfiguration `xml:"device" json:"devices"`
|
||||
ReadOnly bool `xml:"ro,attr" json:"readOnly"`
|
||||
|
||||
@@ -650,8 +650,9 @@ nextFolder:
|
||||
|
||||
if !m.folderSharedWithUnlocked(folder.ID, deviceID) {
|
||||
events.Default.Log(events.FolderRejected, map[string]string{
|
||||
"folder": folder.ID,
|
||||
"device": deviceID.String(),
|
||||
"folder": folder.ID,
|
||||
"folderLabel": folder.Label,
|
||||
"device": deviceID.String(),
|
||||
})
|
||||
l.Infof("Unexpected folder ID %q sent from device %q; ensure that the folder exists and that this device is selected under \"Share With\" in the folder configuration.", folder.ID, deviceID)
|
||||
continue
|
||||
@@ -1530,7 +1531,7 @@ func (m *Model) numHashers(folder string) int {
|
||||
// generateClusterConfig returns a ClusterConfigMessage that is correct for
|
||||
// the given peer device
|
||||
func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.ClusterConfigMessage {
|
||||
cm := protocol.ClusterConfigMessage{
|
||||
message := protocol.ClusterConfigMessage{
|
||||
DeviceName: m.deviceName,
|
||||
ClientName: m.clientName,
|
||||
ClientVersion: m.clientVersion,
|
||||
@@ -1539,8 +1540,9 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
||||
m.fmut.RLock()
|
||||
for _, folder := range m.deviceFolders[device] {
|
||||
folderCfg := m.cfg.Folders()[folder]
|
||||
cr := protocol.Folder{
|
||||
ID: folder,
|
||||
protocolFolder := protocol.Folder{
|
||||
ID: folder,
|
||||
Label: folderCfg.Label,
|
||||
}
|
||||
var flags uint32
|
||||
if folderCfg.ReadOnly {
|
||||
@@ -1552,7 +1554,7 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
||||
if folderCfg.IgnoreDelete {
|
||||
flags |= protocol.FlagFolderIgnoreDelete
|
||||
}
|
||||
cr.Flags = flags
|
||||
protocolFolder.Flags = flags
|
||||
for _, device := range m.folderDevices[folder] {
|
||||
// DeviceID is a value type, but with an underlying array. Copy it
|
||||
// so we don't grab aliases to the same array later on in device[:]
|
||||
@@ -1560,7 +1562,7 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
||||
// TODO: Set read only bit when relevant, and when we have per device
|
||||
// access controls.
|
||||
deviceCfg := m.cfg.Devices()[device]
|
||||
cn := protocol.Device{
|
||||
protocolDevice := protocol.Device{
|
||||
ID: device[:],
|
||||
Name: deviceCfg.Name,
|
||||
Addresses: deviceCfg.Addresses,
|
||||
@@ -1570,15 +1572,15 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
|
||||
}
|
||||
|
||||
if deviceCfg.Introducer {
|
||||
cn.Flags |= protocol.FlagIntroducer
|
||||
protocolDevice.Flags |= protocol.FlagIntroducer
|
||||
}
|
||||
cr.Devices = append(cr.Devices, cn)
|
||||
protocolFolder.Devices = append(protocolFolder.Devices, protocolDevice)
|
||||
}
|
||||
cm.Folders = append(cm.Folders, cr)
|
||||
message.Folders = append(message.Folders, protocolFolder)
|
||||
}
|
||||
m.fmut.RUnlock()
|
||||
|
||||
return cm
|
||||
return message
|
||||
}
|
||||
|
||||
func (m *Model) State(folder string) (string, time.Time, error) {
|
||||
|
||||
@@ -143,6 +143,7 @@ func (o *ClusterConfigMessage) GetOption(key string) string {
|
||||
|
||||
type Folder struct {
|
||||
ID string // max:256
|
||||
Label string // max:256
|
||||
Devices []Device // max:1000000
|
||||
Flags uint32
|
||||
Options []Option // max:64
|
||||
|
||||
@@ -656,6 +656,10 @@ Folder Structure:
|
||||
\ ID (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Label (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Number of Devices |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
@@ -674,6 +678,7 @@ Folder Structure:
|
||||
|
||||
struct Folder {
|
||||
string ID<256>;
|
||||
string Label<256>;
|
||||
Device Devices<1000000>;
|
||||
unsigned int Flags;
|
||||
Option Options<64>;
|
||||
@@ -683,6 +688,7 @@ struct Folder {
|
||||
|
||||
func (o Folder) XDRSize() int {
|
||||
return 4 + len(o.ID) + xdr.Padding(len(o.ID)) +
|
||||
4 + len(o.Label) + xdr.Padding(len(o.Label)) +
|
||||
4 + xdr.SizeOfSlice(o.Devices) + 4 +
|
||||
4 + xdr.SizeOfSlice(o.Options)
|
||||
}
|
||||
@@ -706,6 +712,10 @@ func (o Folder) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
return xdr.ElementSizeExceeded("ID", l, 256)
|
||||
}
|
||||
m.MarshalString(o.ID)
|
||||
if l := len(o.Label); l > 256 {
|
||||
return xdr.ElementSizeExceeded("Label", l, 256)
|
||||
}
|
||||
m.MarshalString(o.Label)
|
||||
if l := len(o.Devices); l > 1000000 {
|
||||
return xdr.ElementSizeExceeded("Devices", l, 1000000)
|
||||
}
|
||||
@@ -734,6 +744,7 @@ func (o *Folder) UnmarshalXDR(bs []byte) error {
|
||||
}
|
||||
func (o *Folder) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
o.ID = u.UnmarshalStringMax(256)
|
||||
o.Label = u.UnmarshalStringMax(256)
|
||||
_DevicesSize := int(u.UnmarshalUint32())
|
||||
if _DevicesSize < 0 {
|
||||
return xdr.ElementSizeExceeded("Devices", _DevicesSize, 1000000)
|
||||
|
||||
Reference in New Issue
Block a user