Permalink
Browse files

Add dos sanitize function (unused).

  • Loading branch information...
1 parent 5be46d6 commit f86261f197bd9aa0a5deff4a38f86b28c104f5b9 @hanwen committed Jun 12, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 fs.go
View
18 fs.go
@@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"os"
+ "strings"
"syscall"
"time"
)
@@ -159,6 +160,23 @@ func (fs *DeviceFs) OnMount(conn *fuse.FileSystemConnector) {
}
}
+
+const forbidden = ":*?\"<>|"
+func SanitizeDosName(name string) string{
+ if strings.IndexAny(name, forbidden) == -1 {
+ return name
+ }
+ dest := make([]byte, len(name))
+ for _, c := range name {
+ if strings.Contains(forbidden, c) {
+ dest = append(dest, '_')
+ } else {
+ dest = append(dest, c)
+ }
+ }
+ return string(dest)
+}
+
////////////////
// files

0 comments on commit f86261f

Please sign in to comment.