Last active
August 29, 2015 14:28
-
-
Save muraiki/19cc7c6889ed61924ba7 to your computer and use it in GitHub Desktop.
Watch a file and chown it once it exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $PATH = '.'; | |
my $USER = 'muraiki'; | |
my $GROUP = 'staff'; | |
IO::Notification.watch_path($PATH)\ | |
.unique(:as(*.path), :expires(1))\ | |
.map(*.path)\ | |
.grep(* ~~ /\.sock/)\ | |
.act(-> $socket { | |
say "Socket created: $socket"; # actually this happens for any I/O on the file, not just creation | |
my $chown_result = run 'chown', "$USER:$GROUP", $socket; | |
say $chown_result == 0 ?? "chown $socket succeeded" !! "chown $socket failed: " ~ $chown_result.exitcode; | |
exit $chown_result == 0 ?? 0 !! $chown_result.exitcode; | |
}); | |
sleep; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The weirdness about checking the value of $chown_result is because
run
is returning an object on failure, which contradicts what's said in https://perl6advent.wordpress.com/2014/12/06/day-06-running-external-programs-from-perl-6/This is true at least for
perl6 version 2015.07.1-151-g5ad8122 built on MoarVM version 2015.07-57-gec051f5