mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
Like we already do with names ending in space or containing invalid characters.
This commit is contained in:
parent
8452fd2ab4
commit
df99237a7f
@ -56,13 +56,23 @@ var windowsDisallowedCharacters = string([]rune{
|
|||||||
})
|
})
|
||||||
|
|
||||||
func WindowsInvalidFilename(name string) bool {
|
func WindowsInvalidFilename(name string) bool {
|
||||||
// None of the path components should end in space
|
// None of the path components should end in space or period, or be a
|
||||||
|
// reserved name.
|
||||||
|
// (https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file)
|
||||||
for _, part := range strings.Split(name, `\`) {
|
for _, part := range strings.Split(name, `\`) {
|
||||||
if len(part) == 0 {
|
if len(part) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if part[len(part)-1] == ' ' {
|
switch part[len(part)-1] {
|
||||||
// Names ending in space are not valid.
|
case ' ', '.':
|
||||||
|
// Names ending in space or period are not valid.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
switch part {
|
||||||
|
case "CON", "PRN", "AUX", "NUL",
|
||||||
|
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
||||||
|
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9":
|
||||||
|
// These reserved names are not valid.
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user