path_helper.go 900 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package path_helper
  2. import "strings"
  3. func FixShareFileProtocolsPath(orgPath string) string {
  4. orgPath = fixSMBPath(orgPath, smbPrefixBase, smbPrefixFull)
  5. orgPath = fixSMBPath(orgPath, afpPrefixBase, afpPrefixFull)
  6. orgPath = fixSMBPath(orgPath, nfsPrefixBase, nfsPrefixFull)
  7. return orgPath
  8. }
  9. func fixSMBPath(orgPath string, prefixBase, prefixFull string) string {
  10. if strings.HasPrefix(orgPath, prefixBase) == true {
  11. // 匹配最基本的前缀
  12. if strings.HasPrefix(orgPath, prefixFull) == true {
  13. // 完全符合
  14. return orgPath
  15. } else {
  16. // 被转义少了一个 '/'
  17. return strings.ReplaceAll(orgPath, prefixBase, prefixFull)
  18. }
  19. } else {
  20. // 无需调整,因为没得 smb 关键词
  21. return orgPath
  22. }
  23. }
  24. const (
  25. smbPrefixBase = "smb:/"
  26. smbPrefixFull = "smb://"
  27. afpPrefixBase = "afp:/"
  28. afpPrefixFull = "afp://"
  29. nfsPrefixBase = "nfs:/"
  30. nfsPrefixFull = "nfs://"
  31. )