path_windows.go 651 B

12345678910111213141516171819202122
  1. package archive
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "strings"
  6. )
  7. // checkSystemDriveAndRemoveDriveLetter is the Windows implementation
  8. // of CheckSystemDriveAndRemoveDriveLetter
  9. func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
  10. if len(path) == 2 && string(path[1]) == ":" {
  11. return "", fmt.Errorf("no relative path specified in %q", path)
  12. }
  13. if !filepath.IsAbs(path) || len(path) < 2 {
  14. return filepath.FromSlash(path), nil
  15. }
  16. if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") {
  17. return "", fmt.Errorf("the specified path is not on the system drive (C:)")
  18. }
  19. return filepath.FromSlash(path[2:]), nil
  20. }