1. my class IO::Spec::Cygwin is IO::Spec::Unix {
  2. method canonpath (Cool:D $patharg) {
  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);
  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 ($file) {
  18. so $file ~~ / ^ [<[A..Z a..z]> ':']? <[\\/]>/; # C:/test
  19. }
  20. method tmpdir {
  21. my %ENV := %*ENV;
  22. my $io;
  23. first( {
  24. if .defined {
  25. $io = .IO;
  26. $io.d && $io.r && $io.w && $io.x;
  27. }
  28. },
  29. %ENV<TMPDIR>,
  30. "/tmp",
  31. %ENV<TMP>,
  32. %ENV<TEMP>,
  33. 'C:/temp',
  34. ) ?? $io !! IO::Path.new(".");
  35. }
  36. # Paths might have a volume, so we use Win32 splitpath and catpath instead
  37. method abs2rel(|c) {
  38. IO::Spec::Win32.abs2rel(|c).subst(:global, '\\', '/');
  39. }
  40. method rel2abs(|c) {
  41. IO::Spec::Win32.rel2abs(|c, :omit-volume).subst(:global, '\\', '/');
  42. }
  43. method splitpath(|c) {
  44. IO::Spec::Win32.splitpath(|c)>>.subst(:global, '\\', '/');
  45. }
  46. method catpath(|c) {
  47. IO::Spec::Win32.catpath(|c).subst(:global, '\\', '/');
  48. }
  49. multi method split(IO::Spec::Cygwin: Cool:D $path) {
  50. IO::Spec::Win32.split($path).map(
  51. { (.key => .value.subst(:global, '\\', '/')) }
  52. );
  53. }
  54. method join(|c) {
  55. IO::Spec::Win32.join(|c).subst(:global, '\\', '/');
  56. }
  57. }