| 1 | package IO::Die; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | #NOTE: This will only chown() one thing at a time. It refuses to support | ||
| 6 | #multiple chown() operations within the same call. This is in order to provide | ||
| 7 | #reliable error reporting. | ||
| 8 | # | ||
| 9 | #You, of course, can still do: IO::Die->chown() for @items; | ||
| 10 | # | ||
| 11 | sub chown { | ||
| 12 | my ( $NS, $uid, $gid, $target, @too_many_args ) = @_; | ||
| 13 | |||
| 14 | #This is here because it’s impossible to do reliable error-checking when | ||
| 15 | #you operate on >1 filesystem node at once. | ||
| 16 | die "Only one path at a time!" if @too_many_args; | ||
| 17 | |||
| 18 | local ( $!, $^E ); | ||
| 19 | |||
| 20 | my $ok = CORE::chown( $uid, $gid, $target ) or do { | ||
| 21 | if ( __is_a_fh($target) ) { | ||
| 22 | $NS->__THROW( 'Chown', uid => $uid, gid => $gid ); | ||
| 23 | } | ||
| 24 | |||
| 25 | $NS->__THROW( 'Chown', uid => $uid, gid => $gid, path => $target ); | ||
| 26 | }; | ||
| 27 | |||
| 28 | return $ok; | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; |