nativemodel_windows.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package protocol
  6. // Windows uses backslashes as file separator and disallows a bunch of
  7. // characters in the filename
  8. import (
  9. "path/filepath"
  10. "strings"
  11. )
  12. var disallowedCharacters = string([]rune{
  13. '<', '>', ':', '"', '|', '?', '*',
  14. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  15. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  16. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  17. 31,
  18. })
  19. type nativeModel struct {
  20. next Model
  21. }
  22. func (m nativeModel) Index(nodeID NodeID, repo string, files []FileInfo) {
  23. for i, f := range files {
  24. if strings.ContainsAny(f.Name, disallowedCharacters) {
  25. files[i].Flags |= FlagInvalid
  26. l.Warnf("File name %q contains invalid characters; marked as invalid.", f.Name)
  27. }
  28. files[i].Name = filepath.FromSlash(f.Name)
  29. }
  30. m.next.Index(nodeID, repo, files)
  31. }
  32. func (m nativeModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
  33. for i, f := range files {
  34. if strings.ContainsAny(f.Name, disallowedCharacters) {
  35. files[i].Flags |= FlagInvalid
  36. l.Warnf("File name %q contains invalid characters; marked as invalid.", f.Name)
  37. }
  38. files[i].Name = filepath.FromSlash(files[i].Name)
  39. }
  40. m.next.IndexUpdate(nodeID, repo, files)
  41. }
  42. func (m nativeModel) Request(nodeID NodeID, repo string, name string, offset int64, size int) ([]byte, error) {
  43. name = filepath.FromSlash(name)
  44. return m.next.Request(nodeID, repo, name, offset, size)
  45. }
  46. func (m nativeModel) ClusterConfig(nodeID NodeID, config ClusterConfigMessage) {
  47. m.next.ClusterConfig(nodeID, config)
  48. }
  49. func (m nativeModel) Close(nodeID NodeID, err error) {
  50. m.next.Close(nodeID, err)
  51. }