wireformat.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package protocol
  7. import (
  8. "context"
  9. "path/filepath"
  10. "golang.org/x/text/unicode/norm"
  11. )
  12. type wireFormatConnection struct {
  13. Connection
  14. }
  15. func (c wireFormatConnection) Index(ctx context.Context, idx *Index) error {
  16. for i := range idx.Files {
  17. idx.Files[i].Name = norm.NFC.String(filepath.ToSlash(idx.Files[i].Name))
  18. }
  19. return c.Connection.Index(ctx, idx)
  20. }
  21. func (c wireFormatConnection) IndexUpdate(ctx context.Context, idxUp *IndexUpdate) error {
  22. for i := range idxUp.Files {
  23. idxUp.Files[i].Name = norm.NFC.String(filepath.ToSlash(idxUp.Files[i].Name))
  24. }
  25. return c.Connection.IndexUpdate(ctx, idxUp)
  26. }
  27. func (c wireFormatConnection) Request(ctx context.Context, req *Request) ([]byte, error) {
  28. req.Name = norm.NFC.String(filepath.ToSlash(req.Name))
  29. return c.Connection.Request(ctx, req)
  30. }