1. my class IO::Spec::Cygwin is IO::Spec::Unix {
  2. method canonpath ($patharg, :$parent) {
  3. my $path = $patharg.Str;
  4. $path.=subst(:g, '\\', '/');
  5. # Handle network path names beginning with double slash
  6. my $node = '';
  7. if $path ~~ s/^ ('//' <-[/]>+) [ '/' | $ ] /\// { #/
  8. $node = ~$0;
  9. }
  10. $node ~ IO::Spec::Unix.canonpath($path, :$parent);
  11. }
  12. method catdir ( *@paths ) {
  13. my $result = IO::Spec::Unix.catdir(@paths);
  14. # Don't create something that looks like a //network/path
  15. $result.subst(/ <[\\\/]> ** 2..*/, '/');
  16. }
  17. method is-absolute ($path) {
  18. nqp::p6bool(
  19. nqp::iseq_i(($_ := nqp::ord($path)), 92) # /^ 「\」 /
  20. || nqp::iseq_i($_, 47) # /^ 「/」 /
  21. || (nqp::eqat($path, ':', 1) # /^ <[A..Z a..z]> ':' [ 「\」 | 「/」 ] /
  22. && ( (nqp::isge_i($_, 65) && nqp::isle_i($_, 90)) # drive letter
  23. || (nqp::isge_i($_, 97) && nqp::isle_i($_, 122)))
  24. && ( nqp::iseq_i(($_ := nqp::ordat($path, 2)), 92) # slash
  25. || nqp::iseq_i($_, 47))))
  26. }
  27. method tmpdir {
  28. my %ENV := %*ENV;
  29. my $io;
  30. first( {
  31. if .defined {
  32. $io = .IO;
  33. $io.d && $io.rwx;
  34. }
  35. },
  36. %ENV<TMPDIR>,
  37. "/tmp",
  38. %ENV<TMP>,
  39. %ENV<TEMP>,
  40. 'C:/temp',
  41. ) ?? $io !! IO::Path.new(".");
  42. }
  43. # Paths might have a volume, so we use Win32 splitpath and catpath instead
  44. method abs2rel(|c) {
  45. IO::Spec::Win32.abs2rel(|c).subst(:global, '\\', '/');
  46. }
  47. method rel2abs(|c) {
  48. IO::Spec::Win32.rel2abs(|c, :omit-volume).subst(:global, '\\', '/');
  49. }
  50. method splitpath(|c) {
  51. IO::Spec::Win32.splitpath(|c)>>.subst(:global, '\\', '/');
  52. }
  53. method catpath(|c) {
  54. IO::Spec::Win32.catpath(|c).subst(:global, '\\', '/');
  55. }
  56. method split(IO::Spec::Cygwin: Cool:D $path) {
  57. IO::Spec::Win32.split($path).map(
  58. { .key => .value.subst(:global, '\\', '/') }
  59. ).List;
  60. }
  61. method join(|c) {
  62. IO::Spec::Win32.join(|c).subst(:global, '\\', '/');
  63. }
  64. }