forked from rakudo/rakudo
/
Path.pm
753 lines (677 loc) · 24.3 KB
/
Path.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
my class Instant { ... }
my class IO::Path is Cool {
has IO::Spec $.SPEC;
has Str $.CWD;
has Str $.path;
has Bool $!is-absolute;
has Str $!abspath; # should be native for faster file tests, but segfaults
has %!parts;
multi method ACCEPTS(IO::Path:D: Cool:D \other) {
nqp::p6bool(nqp::iseq_s($.abspath, nqp::unbox_s(other.IO.abspath)));
}
submethod BUILD(:$!path!, :$!SPEC!, :$!CWD! --> Nil) {
nqp::unless($!path,
die "Must specify something as a path: did you mean '.' for the current directory?"
)
}
method new-from-absolute-path($path, :$SPEC = $*SPEC, Str() :$CWD = $*CWD) {
method !set-absolute() {
$!is-absolute = True;
$!abspath := $path;
self;
}
self.bless(:$path, :$SPEC, :$CWD)!set-absolute;
}
proto method new(|) {*}
multi method new(IO::Path: Str $path, :$SPEC = $*SPEC, Str:D :$CWD) {
self.bless(:$path, :$SPEC, :$CWD);
}
multi method new(IO::Path: Str $path, :$SPEC = $*SPEC, :$CWD = $*CWD) {
self.bless(:$path, :$SPEC, :CWD($CWD.Str));
}
multi method new(IO::Path: Cool $path, :$SPEC = $*SPEC, :$CWD = $*CWD) {
self.bless(:path($path.Str), :$SPEC, :CWD($CWD.Str));
}
multi method new(IO::Path:
:$basename!,
:$dirname = '',
:$volume = '',
:$SPEC = $*SPEC,
Str() :$CWD = $*CWD,
) {
self.bless(:path($SPEC.join($volume,$dirname,$basename)),:$SPEC,:$CWD);
}
multi method new(IO::Path:) {
die "Must specify something as a path: did you mean '.' for the current directory?";
}
method abspath() {
$!abspath //= $!SPEC.rel2abs($!path,$!CWD);
}
method is-absolute() {
$!is-absolute //= $!SPEC.is-absolute($!path);
}
method is-relative() {
!( $!is-absolute //= $!SPEC.is-absolute($!path) );
}
method parts {
%!parts ||= $!SPEC.split($!path);
}
method volume(IO::Path:D:) { %.parts<volume> }
method dirname(IO::Path:D:) { %.parts<dirname> }
method basename(IO::Path:D:) { %.parts<basename> }
my sub EXTENSION-MK-EXTENSION (
str $name, $no-ext, int $part-min, int $part-max = $part-min
) is pure {
my int $offset = nqp::chars($name);
my int $next-offset;
my int $parts;
nqp::while(
nqp::if(
nqp::isne_i( -1,
($next-offset = nqp::rindex($name, '.', nqp::sub_i($offset, 1)))),
nqp::if($offset, nqp::islt_i($parts, $part-max))
),
nqp::stmts(
($offset = $next-offset),
($parts = nqp::add_i($parts, 1))
),
);
nqp::if(
nqp::if(nqp::isle_i($part-min, $parts), nqp::isle_i($parts, $part-max)),
nqp::substr($name, nqp::add_i($offset, 1)),
$no-ext,
)
}
my sub EXTENSION-SUBST ($ext, $base, $subst, $joiner) is pure {
nqp::if(
nqp::defined($ext),
nqp::unless(
nqp::concat(
nqp::if(
nqp::unless( # if extension is empty, check $base to find out if...
nqp::chars($ext), #... it's a missing ext. or empty string ext.
nqp::eqat($base, '.', nqp::sub_i(nqp::chars($base), 1))
),
nqp::substr($base, 0,
nqp::sub_i(nqp::chars($base), nqp::add_i(nqp::chars($ext), 1))
),
$base,
),
nqp::concat($joiner, $subst)
), '.' # use `.` as basename if we ended up with it being empty
),
$base,
)
}
proto method extension(|) {*}
multi method extension(IO::Path:D:) {
nqp::if(
nqp::iseq_i(-1, (my int $offset = nqp::rindex(
(my str $basename = nqp::unbox_s(self.basename)),'.'))),
'', nqp::substr($basename, nqp::add_i($offset, 1))
)
}
multi method extension(IO::Path:D: Int :$parts!) {
EXTENSION-MK-EXTENSION self.basename, '',
nqp::if(
nqp::islt_I(nqp::decont($parts), -2**63), -2**63,
nqp::if( nqp::isgt_I(nqp::decont($parts), 2**63-1), 2**63-1,
nqp::unbox_i($parts),
),
)
}
multi method extension(IO::Path:D: Range :$parts!) {
my ($min, $max) := Rakudo::Internals.RANGE-AS-ints:
$parts, "Can only use numeric, non-NaN Ranges as :parts";
EXTENSION-MK-EXTENSION self.basename, '', $min, $max
}
multi method extension(IO::Path:D:
Str $subst,
Int :$parts = 1, Str :$joiner = nqp::if(nqp::chars($subst), '.', '')
) {
self.new: :dirname(self.dirname), :volume(self.volume),
:$!SPEC, :$!CWD, basename => EXTENSION-SUBST
EXTENSION-MK-EXTENSION(
(my str $base = nqp::unbox_s(self.basename)),
Any, nqp::if(
nqp::islt_I(nqp::decont($parts), -2**63), -2**63,
nqp::if( nqp::isgt_I(nqp::decont($parts), 2**63-1), 2**63-1,
nqp::unbox_i($parts),
),
)
), $base, $subst, $joiner;
}
multi method extension(
Str $subst,
Range :$parts, Str :$joiner = nqp::if(nqp::chars($subst), '.', '')
) {
my ($min, $max) := Rakudo::Internals.RANGE-AS-ints:
$parts, "Can only use numeric, non-NaN Ranges as :parts";
self.new: :dirname(self.dirname), :volume(self.volume),
:$!SPEC, :$!CWD, basename => EXTENSION-SUBST
EXTENSION-MK-EXTENSION(
(my str $base = nqp::unbox_s(self.basename)), Any, $min, $max
), $base, $subst, $joiner
}
# core can't do 'basename handles <Numeric Int>'
method Numeric(IO::Path:D:) { self.basename.Numeric }
method Int (IO::Path:D:) { self.basename.Int }
multi method Str (IO::Path:D:) { $!path }
multi method gist(IO::Path:D:) {
$!is-absolute
?? qq|"$.abspath".IO|
!! qq|"$.path".IO|
}
multi method perl(IO::Path:D:) {
$!is-absolute # attribute now set
?? "{$.abspath.perl}.IO({:$!SPEC.perl})"
!! "{$.path.perl}.IO({:$!SPEC.perl},{:$!CWD.perl})"
}
method succ(IO::Path:D:) {
self.bless(
:path($!SPEC.join($.volume,$.dirname,$.basename.succ)),
:$!SPEC,
:$!CWD,
);
}
method pred(IO::Path:D:) {
self.bless(
:path($!SPEC.join($.volume,$.dirname,$.basename.pred)),
:$!SPEC,
:$!CWD,
);
}
multi method IO(IO::Path:D:) { self }
method open(IO::Path:D: |c) { IO::Handle.new(:path(self)).open(|c) }
#?if moar
method watch(IO::Path:D:) {
IO::Notification.watch-path($.abspath);
}
#?endif
proto method absolute(|) { * }
multi method absolute (IO::Path:D:) { $.abspath }
multi method absolute (IO::Path:D: $CWD) {
self.is-absolute
?? $.abspath
!! $!SPEC.rel2abs($!path, $CWD);
}
method relative (IO::Path:D: $CWD = $*CWD) {
$!SPEC.abs2rel($.abspath, $CWD);
}
method cleanup (IO::Path:D:) {
self.bless(:path($!SPEC.canonpath($!path)), :$!SPEC, :$!CWD);
}
method resolve (IO::Path:D:) {
# XXXX: Not portable yet; assumes POSIX semantics
my int $max-depth = 256;
my str $sep = $!SPEC.dir-sep;
my str $cur = $!SPEC.curdir;
my str $up = $!SPEC.updir;
my str $empty = '';
my str $resolved = $empty;
my Mu $res-list := nqp::list_s();
my Mu $parts := nqp::split($sep, nqp::unbox_s(self.absolute));
while $parts {
fail "Resolved path too deep!"
if $max-depth < nqp::elems($res-list) + nqp::elems($parts);
# Grab next unprocessed part, check for '', '.', '..'
my str $part = nqp::shift($parts);
next if nqp::iseq_s($part, $empty) || nqp::iseq_s($part, $cur);
if nqp::iseq_s($part, $up) {
next unless $res-list;
nqp::pop_s($res-list);
$resolved = $res-list ?? $sep ~ nqp::join($sep, $res-list)
!! $empty;
next;
}
# Normal part, set as next path to test
my str $next = nqp::concat($resolved, nqp::concat($sep, $part));
# Path part doesn't exist; handle rest in non-resolving mode
if !nqp::stat($next, nqp::const::STAT_EXISTS) {
$resolved = $next;
while $parts {
$part = nqp::shift($parts);
next if nqp::iseq_s($part, $empty) || nqp::iseq_s($part, $cur);
$resolved = nqp::concat($resolved, nqp::concat($sep, $part));
}
}
# Symlink; read it and act on absolute or relative link
elsif nqp::fileislink($next) {
my str $link = nqp::readlink($next);
my Mu $link-parts := nqp::split($sep, $link);
next unless $link-parts;
# Symlink to absolute path
if nqp::iseq_s($link-parts[0], $empty) {
$resolved = nqp::shift($link-parts);
$res-list := nqp::list_s();
}
nqp::unshift($parts, nqp::pop($link-parts))
while $link-parts;
}
# Just a plain old path part, so append it and go on
else {
$resolved = $next;
nqp::push_s($res-list, $part);
}
}
$resolved = $sep unless nqp::chars($resolved);
IO::Path.new-from-absolute-path($resolved,:$!SPEC,:CWD(self));
}
method parent(IO::Path:D:) { # XXX needs work
my $curdir := $!SPEC.curdir;
my $updir := $!SPEC.updir;
if self.is-absolute {
return self.bless(
:path($!SPEC.join($.volume, $.dirname, '')),
:$!SPEC,
:$!CWD,
);
}
elsif $.dirname eq $curdir and $.basename eq $curdir {
return self.bless(
:path($!SPEC.join($.volume,$curdir,$updir)),
:$!SPEC,
:$!CWD,
);
}
elsif $.dirname eq $curdir && $.basename eq $updir
or !grep({$_ ne $updir}, $!SPEC.splitdir($.dirname)) {
return self.bless( # If all updirs, then add one more
:path($!SPEC.join($.volume,$!SPEC.catdir($.dirname,$updir),$.basename)),
:$!SPEC,
:$!CWD,
);
}
else {
return self.bless(
:path($!SPEC.join($.volume, $.dirname, '')),
:$!SPEC,
:$!CWD,
);
}
}
method child (IO::Path:D: \child) {
self.bless(
:path( $!SPEC.join('', $!path,
nqp::if(nqp::istype(child, Str), child, child.Str)
)),
:$!SPEC, :$!CWD
);
}
method concat-with (IO::Path:D: Str() \what) {
self.bless: :path($!SPEC.join: '', $!path, what), :$!SPEC, :$!CWD;
}
proto method chdir(|) { * }
multi method chdir(IO::Path:D: Str() $path, :$test!) {
DEPRECATED(
:what<:$test argument>,
'individual named parameters (e.g. :r, :w, :x)',
"v2017.03.101.ga.5800.a.1", "v6.d", :up(*),
);
self.chdir: $path, |$test.words.map(* => True).Hash;
}
multi method chdir(
IO::Path:D: Str() $path is copy, :$d = True, :$r, :$w, :$x,
) {
unless $!SPEC.is-absolute($path) {
my ($volume,$dirs) = $!SPEC.splitpath(self.abspath, :nofile);
my @dirs = $!SPEC.splitdir($dirs);
@dirs.shift; # the first is always empty for absolute dirs
for $!SPEC.splitdir($path) -> $dir {
if $dir eq '..' {
@dirs.pop if @dirs;
}
elsif $dir ne '.' {
@dirs.push: $dir;
}
}
@dirs.push('') if !@dirs; # need at least the rootdir
$path = join($!SPEC.dir-sep, $volume, @dirs);
}
my $dir = IO::Path.new-from-absolute-path($path,:$!SPEC,:CWD(self));
nqp::stmts(
nqp::unless(
nqp::unless(nqp::isfalse($d), $dir.d),
fail X::IO::Chdir.new: :$path, :os-error(
nqp::if($dir.e, 'is not a directory', 'does not exist')
)
),
nqp::unless(
nqp::unless(nqp::isfalse($r), $dir.r),
fail X::IO::Chdir.new: :$path, :os-error("did not pass :r test")
),
nqp::unless(
nqp::unless(nqp::isfalse($w), $dir.w),
fail X::IO::Chdir.new: :$path, :os-error("did not pass :w test")
),
nqp::unless(
nqp::unless(nqp::isfalse($x), $dir.x),
fail X::IO::Chdir.new: :$path, :os-error("did not pass :x test")
),
$dir
)
}
proto method rename(|) { * }
multi method rename(IO::Path:D: IO::Path:D $to, :$createonly) {
if $createonly and $to.e {
fail X::IO::Rename.new(
:from($.abspath),
:$to,
:os-error(':createonly specified and destination exists'),
);
}
nqp::rename($.abspath, nqp::unbox_s($to.abspath));
CATCH { default {
fail X::IO::Rename.new(
:from($!abspath), :to($to.abspath), :os-error(.Str) );
} }
True;
}
multi method rename(IO::Path:D: $to, :$CWD = $*CWD, |c) {
self.rename($to.IO(:$!SPEC,:$CWD),|c);
}
proto method copy(|) { * }
multi method copy(IO::Path:D: IO::Path:D $to, :$createonly) {
if $createonly and $to.e {
fail X::IO::Copy.new(
:from($.abspath),
:$to,
:os-error(':createonly specified and destination exists'),
);
}
nqp::copy($.abspath, nqp::unbox_s($to.abspath));
CATCH { default {
fail X::IO::Copy.new(
:from($!abspath), :$to, :os-error(.Str) );
} }
True;
}
multi method copy(IO::Path:D: $to, :$CWD = $*CWD, |c) {
self.copy($to.IO(:$!SPEC,:$CWD),|c);
}
method move(IO::Path:D: |c) {
my $result = self.copy(|c);
fail X::IO::Move.new(
:from($result.exception.from),
:to($result.exception.to),
:os-error($result.exception.os-error),
) unless $result.defined;
$result = self.unlink();
fail X::IO::Move.new(
:from($result.exception.from),
:to($result.exception.to),
:os-error($result.exception.os-error),
) unless $result.defined;
True
}
method chmod(IO::Path:D: Int() $mode) {
nqp::chmod($.abspath, nqp::unbox_i($mode));
CATCH { default {
fail X::IO::Chmod.new(
:path($!abspath), :$mode, :os-error(.Str) );
} }
True;
}
method unlink(IO::Path:D:) {
nqp::unlink($.abspath);
CATCH { default {
fail X::IO::Unlink.new( :path($!abspath), os-error => .Str );
} }
True;
}
method symlink(IO::Path:D: $name is copy, :$CWD = $*CWD) {
$name = $name.IO(:$!SPEC,:$CWD).path;
nqp::symlink(nqp::unbox_s($name), $.abspath);
CATCH { default {
fail X::IO::Symlink.new(:target($!abspath), :$name, os-error => .Str);
} }
True;
}
method link(IO::Path:D: $name is copy, :$CWD = $*CWD) {
$name = $name.IO(:$!SPEC,:$CWD).path;
nqp::link(nqp::unbox_s($name), $.abspath);
CATCH { default {
fail X::IO::Link.new(:target($!abspath), :$name, os-error => .Str);
} }
True;
}
method mkdir(IO::Path:D: $mode = 0o777) {
nqp::mkdir($.abspath, $mode);
CATCH { default {
fail X::IO::Mkdir.new(:path($!abspath), :$mode, os-error => .Str);
} }
True;
}
method rmdir(IO::Path:D:) {
nqp::rmdir($.abspath);
CATCH { default {
fail X::IO::Rmdir.new(:path($!abspath), os-error => .Str);
} }
True;
}
proto method dir(|) {*} # make it possible to augment with multies from modulespace
multi method dir(IO::Path:D:
Mu :$test = $*SPEC.curupdir,
:$absolute,
:$Str,
:$CWD = $*CWD,
) {
CATCH { default {
fail X::IO::Dir.new(
:path($.abspath), :os-error(.Str) );
} }
my str $dir-sep = $!SPEC.dir-sep;
my int $relative = !$absolute && !$.is-absolute;
my str $abspath = $.abspath.ends-with($dir-sep)
?? $.abspath
!! $.abspath ~ $dir-sep;
my str $path = $!path eq '.' || $!path eq $dir-sep
?? ''
!! $!path.ends-with($dir-sep)
?? $!path
!! $!path ~ $dir-sep;
my Mu $dirh := nqp::opendir(nqp::unbox_s($.abspath));
gather {
#?if jvm
for <. ..> -> $elem {
if $test.ACCEPTS($elem) {
$Str
?? !$absolute
?? take $path ~ $elem
!! take $abspath ~ $elem
!! !$absolute
?? take IO::Path.new($path ~ $elem,:$!SPEC,:$CWD)
!! take IO::Path.new-from-absolute-path($abspath ~ $elem,:$!SPEC,:$CWD);
}
}
#?endif
nqp::until(
nqp::isnull_s(my str $str_elem = nqp::nextfiledir($dirh))
|| nqp::iseq_i(nqp::chars($str_elem),0),
nqp::if(
$test.ACCEPTS($str_elem),
nqp::if(
$Str,
(take
nqp::concat(nqp::if($relative,$path,$abspath),$str_elem)),
nqp::if(
$relative,
(take IO::Path.new(
nqp::concat($path,$str_elem),:$!SPEC,:$CWD)),
(take IO::Path.new-from-absolute-path(
nqp::concat($abspath,$str_elem),:$!SPEC,:$CWD))
)
)
)
);
nqp::closedir($dirh);
}
}
proto method slurp() { * }
multi method slurp(IO::Path:D:) {
# clean call, try the fast way
if nqp::iseq_i(nqp::elems(nqp::getattr(%_,Map,'$!storage')),0)
&& nqp::open(self.abspath,"r") -> $PIO {
LEAVE nqp::closefh(nqp::decont($PIO));
nqp::p6box_s(nqp::readallfh(nqp::decont($PIO)))
}
# need to do the slow way
else {
my $handle = self.open;
$handle // $handle.throw;
LEAVE $handle.close;
my Mu $PIO := nqp::getattr(nqp::decont($handle),IO::Handle,'$!PIO');
if %_<bin> {
my $res;
# normal file
if Rakudo::Internals.FILETEST-S(self.abspath) -> int $size {
$res := nqp::readfh($PIO,buf8.new,$size)
}
# spooky file with zero size?
else {
$res := buf8.new();
loop {
my $buf := nqp::readfh($PIO,buf8.new,0x100000);
last unless nqp::elems($buf);
$res.append($buf);
}
}
$res
}
else {
$handle.encoding($_) with %_<enc>;
nqp::p6box_s(nqp::readallfh($PIO))
}
}
}
method spurt(IO::Path:D: $data, :$enc = 'utf8', :$append, :$createonly) {
my $fh := self.open:
:$enc, :bin(nqp::istype($data, Blob)),
:mode<wo>, :create, :exclusive($createonly),
:$append, :truncate(
nqp::if(nqp::isfalse($append), nqp::isfalse($createonly))
);
nqp::if( nqp::istype($fh, Failure), $fh, $fh.spurt($data, :close) )
}
proto method lines(|) { * }
multi method lines(IO::Path:D: $limit = Whatever, |c) {
my $handle = self.open(|c);
LEAVE $handle.close;
my $buf := nqp::create(IterationBuffer);
nqp::istype($limit,Whatever) || $limit == Inf
?? $handle.iterator.push-all($buf)
!! $handle.iterator.push-exactly($buf,$limit.Int);
Seq.new(Rakudo::Iterator.ReifiedList($buf))
}
proto method comb(|) { * }
multi method comb(IO::Path:D: Cool:D $comber = "", |c) {
self.open(|c).comb($comber, :close);
}
multi method comb(IO::Path:D: Int:D $size, |c) {
self.open(|c).comb($size, :close);
}
multi method comb(IO::Path:D: Regex:D $comber, |c) {
self.open(|c).comb($comber, :close);
}
multi method split(IO::Path:D: Str:D $splitter = "", |c) {
self.open(|c).split($splitter, :close);
}
multi method split(IO::Path:D: Regex:D $splitter, |c) {
self.open(|c).split($splitter, :close);
}
proto method words(|) { * }
multi method words(IO::Path:D: |c) {
self.open(|c).words(:close);
}
method e(--> Bool:D) {
?Rakudo::Internals.FILETEST-E($.abspath) # must be $.abspath
}
method d(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-D($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<d>))
}
method f(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-F($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<f>))
}
method s(--> Int:D) {
$.e
?? Rakudo::Internals.FILETEST-S($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<s>))
}
method l(--> Bool:D) {
?Rakudo::Internals.FILETEST-LE($.abspath)
?? ?Rakudo::Internals.FILETEST-L($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<l>))
}
method r(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-R($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<r>))
}
method w(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-W($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<w>))
}
method rw(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-RW($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<rw>))
}
method x(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-X($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<x>))
}
method rwx(--> Bool:D) {
$.e
?? ?Rakudo::Internals.FILETEST-RWX($!abspath)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<rwx>))
}
method z(--> Bool:D) {
$.e
?? $.f
?? ?Rakudo::Internals.FILETEST-Z($!abspath)
!! Failure.new( X::IO::NotAFile.new(:path(~self),:trying<z>))
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<z>))
}
method modified(--> Instant:D) {
$.e
?? Instant.from-posix(Rakudo::Internals.FILETEST-MODIFIED($!abspath))
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<modified>))
}
method accessed(--> Instant:D) {
$.e
?? Instant.from-posix(Rakudo::Internals.FILETEST-ACCESSED($!abspath))
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<accessed>))
}
method changed(--> Instant:D) {
$.e
?? Instant.from-posix(Rakudo::Internals.FILETEST-CHANGED($!abspath))
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<changed>))
}
method mode(--> IntStr:D) {
$.e
?? nqp::stmts(
(my int $mode = nqp::stat($!abspath, nqp::const::STAT_PLATFORM_MODE) +& 0o7777),
IntStr.new($mode, sprintf('%04o', $mode))
)
!! Failure.new(X::IO::DoesNotExist.new(:path(~self),:trying<mode>))
}
}
my class IO::Path::Cygwin is IO::Path {
method new(|c) { IO::Path.new(|c, :SPEC(IO::Spec::Cygwin) ) }
}
my class IO::Path::QNX is IO::Path {
method new(|c) { IO::Path.new(|c, :SPEC(IO::Spec::QNX) ) }
}
my class IO::Path::Unix is IO::Path {
method new(|c) { IO::Path.new(|c, :SPEC(IO::Spec::Unix) ) }
}
my class IO::Path::Win32 is IO::Path {
method new(|c) { IO::Path.new(|c, :SPEC(IO::Spec::Win32) ) }
}
# vim: ft=perl6 expandtab sw=4