safeName maps a human instruction name to a filesystem-safe basename by replacing every character outside [A-Za-z0-9._-] with '_'.
(name string)
| 17 | // safeName maps a human instruction name to a filesystem-safe basename by |
| 18 | // replacing every character outside [A-Za-z0-9._-] with '_'. |
| 19 | func safeName(name string) string { |
| 20 | var b strings.Builder |
| 21 | for _, r := range name { |
| 22 | switch { |
| 23 | case r >= 'A' && r <= 'Z', r >= 'a' && r <= 'z', r >= '0' && r <= '9', r == '.', r == '_', r == '-': |
| 24 | b.WriteRune(r) |
| 25 | default: |
| 26 | b.WriteByte('_') |
| 27 | } |
| 28 | } |
| 29 | return b.String() |
| 30 | } |
| 31 | |
| 32 | // managedFilePath returns the absolute path of the managed file for name. |
| 33 | func managedFilePath(name string) string { |