Skip to content

Instantly share code, notes, and snippets.

@muraiki
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muraiki/19cc7c6889ed61924ba7 to your computer and use it in GitHub Desktop.
Save muraiki/19cc7c6889ed61924ba7 to your computer and use it in GitHub Desktop.
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
Copy link
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