Skip to content

Commit e4efe6d

Browse files
author
8ward
committed
Improved task hook check
* Replaced own link resolution routine with Cwd::abs_path * Moved hook check before the tmux session is created to prevent creation if hook is not properly set up
1 parent 5af249b commit e4efe6d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

task-dashboard

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ tmux session. If the hook gets triggered the views will be updated.
2222
=cut
2323

2424

25+
use Cwd qw(abs_path);
2526
use File::Basename;
2627
use Getopt::Long;
2728
use JSON::PP qw(decode_json);
@@ -86,6 +87,9 @@ if (@ARGV == 6) {
8687
my $width = $config->{width} || $DEFAULT{TMUX_WIDTH};
8788
my $height = $config->{height} || $DEFAULT{TMUX_HEIGHT};
8889

90+
# Check hook link before creating tmux session
91+
ensure_hook_link();
92+
8993
# Setup layout
9094
tmux('new', '-s', $session, '-n', $window, '-d', '-x', $width, '-y', $height, $MINIMAL_BASH);
9195
tmux('set', '-t', "$session:$window", 'status', "off");
@@ -100,7 +104,6 @@ if (@ARGV == 6) {
100104
tmux('send-keys', '-t', "$session:$window.%$idx", "clear; $command", 'Enter');
101105
}
102106

103-
ensure_hook_link();
104107
tmux('attach', '-t', $session) if $config->{'auto-attach'};
105108
}
106109

@@ -183,21 +186,15 @@ sub dashboard_is_running {
183186
}
184187

185188
sub ensure_hook_link {
186-
my $target = resolve_link($0);
189+
my $target = abs_path($0);
187190
my $symlink = task_config('rc.data.location') . '/hooks/on-exit_dashboard';
188191
if (-e $symlink) {
189-
die "Hook symlink points to another location!\n" if resolve_link($symlink) ne $target;
192+
die "Hook symlink points to another location!\n" if abs_path($symlink) ne $target;
190193
} else {
191194
symlink $target, $symlink;
192195
}
193196
}
194197

195-
sub resolve_link {
196-
my $target = shift;
197-
$target = readlink $target while -l $target;
198-
return $target;
199-
}
200-
201198
sub task_config {
202199
chomp (my $output = `task rc.verbose:nothing rc.hooks:off _get @_`);
203200
$output =~ s/^~/$ENV{HOME}/; # Tilde expansion

0 commit comments

Comments
 (0)