Skip to content

Commit 3145979

Browse files
committed
[io grant] Document IO::Path.child-secure
Rakudo impl: rakudo/rakudo@1887114dd8 Tests: Raku/roast@f3c5dae288
1 parent 4ca7f68 commit 3145979

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

doc/Type/IO/Path.pod6

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ C<IO::Path>.
132132
"foo/bar".IO.concat-with("../meow") .resolve.relative.say; # OUTPUT: «foo/meow␤»
133133
"foo/bar".IO.concat-with("../../") .resolve.relative.say; # OUTPUT: «.␤»
134134
135+
=head2 method child
136+
137+
method child(IO::Path:D: Str() $childname --> IO::Path:D)
138+
139+
Alias for L«C<.concat-with>|/routine/concat-with». See also
140+
L«C<.child-secure>|/routine/child-secure»
141+
142+
=head2 method child-secure
143+
144+
method child-secure(IO::Path:D: Str() $childname --> IO::Path:D)
145+
146+
Same as L«C<.child>|/routine/child», except it will
147+
B«fully L<resolve|/routine/resolve>» the resultant path and check that it is in
148+
fact a child of the invocant. On success, returns the resultant path;
149+
L«fails|/routine/fail» with C<X::IO::Resolve> if the path could not be
150+
completely resolved or with C<X::IO::NotAChild> if the resultant path is not
151+
a child of the invocant.
152+
153+
B<Note:> since the path has to be fully resolved, the method can still fail
154+
with C<X::IO::Resolve> even for paths that would be child paths, if some of
155+
the directories do not exist yet. The last part of the path does not have to
156+
exist for the routine to succeed.
157+
158+
=for code :skip-test
159+
my $parent = 'foo'.IO.mkdir;
160+
say $parent.child-secure: 'bar'; # OUTPUT: «"foo/bar".IO␤»
161+
say $parent.child-secure: '../bar'; # Fails with X::IO::NotAChild
162+
say $parent.child-secure: 'bar/ber'; # Fails with X::IO::Resolve
163+
164+
$parent.child('bar').mkdir; # create 'bar' so the call below succeeds
165+
say $parent.child-secure: 'bar/ber'; # OUTPUT: «"foo/bar/ber".IO␤»
166+
135167
=head2 method extension
136168
137169
Defined as:
@@ -300,16 +332,6 @@ Removes the last portion of the path and returns the result as a new C<IO::Path>
300332
my $io = IO::Path.new( "/etc/passwd" );
301333
say $io.parent; # OUTPUT: «"/etc".IO␤»
302334
303-
=head2 method child
304-
305-
method child(IO::Path:D: $childname --> IO::Path)
306-
307-
Appends C<$childname> to the end of the path, adding path separators where
308-
needed and returns the result as a new C<IO::Path>.
309-
310-
my $io = IO::Path.new( "/bin" );
311-
say $io.child('netstat'); # OUTPUT: «"/bin/netstat".IO␤»
312-
313335
=head2 method resolve
314336
315337
method resolve(IO::Path:D: :$completely --> IO::Path)

0 commit comments

Comments
 (0)