From df65247325c3e935ee3d15fe4fb0f3ed678afdab Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 25 Aug 2014 08:47:59 +0200 Subject: [PATCH] Increase max path length 1024 -> 8192 bytes (fixes #551) PATH_MAX seems to be 4096 most of the time; Windows limit is much lower. --- files/set_test.go | 30 ++++++++++++++++++++++++++++++ protocol/message.go | 6 +++--- protocol/message_xdr.go | 18 +++++++++--------- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/files/set_test.go b/files/set_test.go index 374eb9cf3..79f33be6c 100644 --- a/files/set_test.go +++ b/files/set_test.go @@ -5,6 +5,7 @@ package files_test import ( + "bytes" "fmt" "sort" "testing" @@ -596,6 +597,35 @@ func TestLocalVersion(t *testing.T) { } } +func TestLongPath(t *testing.T) { + db, err := leveldb.Open(storage.NewMemStorage(), nil) + if err != nil { + t.Fatal(err) + } + + s := files.NewSet("test", db) + + var b bytes.Buffer + for i := 0; i < 100; i++ { + b.WriteString("012345678901234567890123456789012345678901234567890") + } + name := b.String() // 5000 characters + + local := []protocol.FileInfo{ + protocol.FileInfo{Name: string(name), Version: 1000}, + } + + s.ReplaceWithDelete(protocol.LocalNodeID, local) + + gf := globalList(s) + if l := len(gf); l != 1 { + t.Fatalf("Incorrect len %d != 1 for global list", l) + } + if gf[0].Name != local[0].Name { + t.Error("Incorrect long filename;\n%q !=\n%q", gf[0].Name, local[0].Name) + } +} + /* var gf protocol.FileInfo diff --git a/protocol/message.go b/protocol/message.go index 37c9296ea..954ac13ae 100644 --- a/protocol/message.go +++ b/protocol/message.go @@ -12,7 +12,7 @@ type IndexMessage struct { } type FileInfo struct { - Name string // max:1024 + Name string // max:8192 Flags uint32 Modified int64 Version uint64 @@ -41,7 +41,7 @@ func (f FileInfo) IsDeleted() bool { // Used for unmarshalling a FileInfo structure but skipping the actual block list type FileInfoTruncated struct { - Name string // max:1024 + Name string // max:8192 Flags uint32 Modified int64 Version uint64 @@ -82,7 +82,7 @@ func (b BlockInfo) String() string { type RequestMessage struct { Repository string // max:64 - Name string // max:1024 + Name string // max:8192 Offset uint64 Size uint32 } diff --git a/protocol/message_xdr.go b/protocol/message_xdr.go index 3f1c0631c..11a11da34 100644 --- a/protocol/message_xdr.go +++ b/protocol/message_xdr.go @@ -127,7 +127,7 @@ FileInfo Structure: struct FileInfo { - string Name<1024>; + string Name<8192>; unsigned int Flags; hyper Modified; unsigned hyper Version; @@ -154,7 +154,7 @@ func (o FileInfo) AppendXDR(bs []byte) []byte { } func (o FileInfo) encodeXDR(xw *xdr.Writer) (int, error) { - if len(o.Name) > 1024 { + if len(o.Name) > 8192 { return xw.Tot(), xdr.ErrElementSizeExceeded } xw.WriteString(o.Name) @@ -184,7 +184,7 @@ func (o *FileInfo) UnmarshalXDR(bs []byte) error { } func (o *FileInfo) decodeXDR(xr *xdr.Reader) error { - o.Name = xr.ReadStringMax(1024) + o.Name = xr.ReadStringMax(8192) o.Flags = xr.ReadUint32() o.Modified = int64(xr.ReadUint64()) o.Version = xr.ReadUint64() @@ -229,7 +229,7 @@ FileInfoTruncated Structure: struct FileInfoTruncated { - string Name<1024>; + string Name<8192>; unsigned int Flags; hyper Modified; unsigned hyper Version; @@ -256,7 +256,7 @@ func (o FileInfoTruncated) AppendXDR(bs []byte) []byte { } func (o FileInfoTruncated) encodeXDR(xw *xdr.Writer) (int, error) { - if len(o.Name) > 1024 { + if len(o.Name) > 8192 { return xw.Tot(), xdr.ErrElementSizeExceeded } xw.WriteString(o.Name) @@ -280,7 +280,7 @@ func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error { } func (o *FileInfoTruncated) decodeXDR(xr *xdr.Reader) error { - o.Name = xr.ReadStringMax(1024) + o.Name = xr.ReadStringMax(8192) o.Flags = xr.ReadUint32() o.Modified = int64(xr.ReadUint64()) o.Version = xr.ReadUint64() @@ -384,7 +384,7 @@ RequestMessage Structure: struct RequestMessage { string Repository<64>; - string Name<1024>; + string Name<8192>; unsigned hyper Offset; unsigned int Size; } @@ -412,7 +412,7 @@ func (o RequestMessage) encodeXDR(xw *xdr.Writer) (int, error) { return xw.Tot(), xdr.ErrElementSizeExceeded } xw.WriteString(o.Repository) - if len(o.Name) > 1024 { + if len(o.Name) > 8192 { return xw.Tot(), xdr.ErrElementSizeExceeded } xw.WriteString(o.Name) @@ -434,7 +434,7 @@ func (o *RequestMessage) UnmarshalXDR(bs []byte) error { func (o *RequestMessage) decodeXDR(xr *xdr.Reader) error { o.Repository = xr.ReadStringMax(64) - o.Name = xr.ReadStringMax(1024) + o.Name = xr.ReadStringMax(8192) o.Offset = xr.ReadUint64() o.Size = xr.ReadUint32() return xr.Error()