| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package NVMPL::Platform::Unix; |
|
2
|
2
|
|
|
2
|
|
345873
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
92
|
|
|
3
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
204
|
|
|
4
|
2
|
|
|
2
|
|
19
|
use feature 'say'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
263
|
|
|
5
|
2
|
|
|
2
|
|
16
|
use File::Spec; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
119
|
|
|
6
|
2
|
|
|
2
|
|
15
|
use File::Path qw(make_path remove_tree); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
192
|
|
|
7
|
2
|
|
|
2
|
|
726
|
use File::Copy qw(move); |
|
|
2
|
|
|
|
|
4679
|
|
|
|
2
|
|
|
|
|
232
|
|
|
8
|
2
|
|
|
2
|
|
629
|
use NVMPL::Utils qw(log_info log_warn log_error); |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
2035
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
11
|
|
|
|
|
|
|
# Create a symlink safely |
|
12
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub create_symlink { |
|
15
|
1
|
|
|
1
|
0
|
6429
|
my ($target, $link) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
50
|
33
|
|
|
51
|
if (-l $link || -e $link) { |
|
18
|
0
|
0
|
|
|
|
0
|
unlink $link or log_warn("Could not remove existing link $link: $!"); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
50
|
0
|
|
|
158
|
symlink($target, $link) |
|
22
|
|
|
|
|
|
|
or log_error("Failed to create symlink: $!") and return 0; |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
12
|
log_info("Created symlink: $link -> $target"); |
|
25
|
1
|
|
|
|
|
134
|
return 1; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
29
|
|
|
|
|
|
|
# Remove a version directory safely |
|
30
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub remove_version_dir { |
|
33
|
1
|
|
|
1
|
0
|
5798
|
my ($dir) = @_; |
|
34
|
1
|
50
|
|
|
|
26
|
if (-d $dir) { |
|
35
|
1
|
|
|
|
|
546
|
remove_tree($dir, { safe => 1 }); |
|
36
|
1
|
|
|
|
|
15
|
log_info("Removed directory: $dir"); |
|
37
|
1
|
|
|
|
|
99
|
return 1; |
|
38
|
|
|
|
|
|
|
} else { |
|
39
|
0
|
|
|
|
|
0
|
log_warn("Directory not found: $dir"); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
44
|
|
|
|
|
|
|
# Extract a .tar.xz archive into target directory |
|
45
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub extract_tarball { |
|
48
|
0
|
|
|
0
|
0
|
0
|
my ($archive, $target_dir) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
log_info("Extracting $archive to $target_dir"); |
|
51
|
0
|
0
|
|
|
|
0
|
make_path($target_dir) unless -d $target_dir; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $cmd = "tar -xJf '$archive' -C '$target_dir'"; |
|
54
|
0
|
0
|
|
|
|
0
|
system($cmd) == 0 |
|
55
|
|
|
|
|
|
|
or die "Extraction failed: $!"; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
opendir(my $dh, $target_dir) or return; |
|
58
|
0
|
0
|
|
|
|
0
|
my @subdirs = grep { /^node-v/ && -d "$target_dir/$_" } readdir($dh); |
|
|
0
|
|
|
|
|
0
|
|
|
59
|
0
|
|
|
|
|
0
|
closedir $dh; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
0
|
if (@subdirs == 1) { |
|
62
|
0
|
|
|
|
|
0
|
my $inner = File::Spec->catdir($target_dir, $subdirs[0]); |
|
63
|
0
|
0
|
|
|
|
0
|
system("mv '$inner'/& '$target_dir'/") == 0 |
|
64
|
|
|
|
|
|
|
or log_warn("could not flatten directory $inner"); |
|
65
|
0
|
|
|
|
|
0
|
remove_tree($inner, { safe => 1 }); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
0
|
log_info("Extraction complete"); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
72
|
|
|
|
|
|
|
# Get Node binary path for current version |
|
73
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub node_bin_path { |
|
76
|
3
|
|
|
3
|
0
|
5869
|
my ($base_install_dir) = @_; |
|
77
|
3
|
|
|
|
|
39
|
return File::Spec->catfile($base_install_dir, 'versions', 'current', 'bin'); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
81
|
|
|
|
|
|
|
# Update PATH for current shell (prints export command) |
|
82
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub export_path_snippet { |
|
85
|
1
|
|
|
1
|
0
|
5840
|
my ($base_install_dir) = @_; |
|
86
|
1
|
|
|
|
|
5
|
my $bin = node_bin_path($base_install_dir); |
|
87
|
1
|
|
|
|
|
16
|
say "export PATH=\"$bin:\$PATH\""; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |