types/model: make Name.Filepath substitute colons in host with ("%")
This makes the filepath legal on all supported platforms. Fixes #4088
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -24,3 +25,44 @@ func fixBlobs(dir string) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// fixManifests walks the provided dir and replaces (":") to ("%") for all
|
||||
// manifest files on non-Windows systems.
|
||||
func fixManifests(dir string) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
return nil
|
||||
}
|
||||
return filepath.Walk(dir, func(oldPath string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var partNum int
|
||||
newPath := []byte(oldPath)
|
||||
for i := len(newPath) - 1; i >= 0; i-- {
|
||||
if partNum > 3 {
|
||||
break
|
||||
}
|
||||
if partNum == 3 {
|
||||
if newPath[i] == ':' {
|
||||
newPath[i] = '%'
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
if newPath[i] == '/' {
|
||||
partNum++
|
||||
}
|
||||
}
|
||||
|
||||
newDir, _ := filepath.Split(string(newPath))
|
||||
if err := os.MkdirAll(newDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Rename(oldPath, string(newPath))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user