Skip to content

Instantly share code, notes, and snippets.

@muraiki muraiki/watch_and_chown.p6
Last active Aug 29, 2015

Embed
What would you like to do?
Watch a file and chown it once it exists
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;
@muraiki

This comment has been minimized.

Copy link
Owner Author

muraiki commented Aug 25, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.