Skip to content

Commit 1f11b89

Browse files
authored
Merge pull request #850 from EDM115/master
fix: works when ran through a symlink, #849
2 parents 465ed6d + 237c5e3 commit 1f11b89

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Unix/AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ https://github.com/Inventitech
3131
https://github.com/zhangzqs
3232
https://github.com/drkameleon
3333
https://github.com/jackos
34-
https://github.com/Aerek-Yasa
34+
https://github.com/Aerek-Yasa
35+
https://github.com/EDM115

Unix/cloc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ if ($ON_WINDOWS and $ENV{'SHELL'}) {
111111
}
112112
}
113113

114+
use Cwd "abs_path";
115+
use File::Spec;
116+
# Fix for issues when runing cloc through a symlink on Windows
117+
# e.g. : it have been installed with Winget
118+
# See https://github.com/AlDanial/cloc/issues/849
119+
if ($ON_WINDOWS) {
120+
my $exec_path = abs_path($0);
121+
if (-l $0) {
122+
$exec_path = abs_path(readlink($0));
123+
}
124+
$0 = $exec_path;
125+
}
126+
114127
my $HAVE_Win32_Long_Path = 0;
115128
# Win32::LongPath is an optional dependency that when available on
116129
# Windows will be used to support reading files past the 255 char

cloc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ if ($ON_WINDOWS and $ENV{'SHELL'}) {
136136
}
137137
}
138138

139+
use Cwd "abs_path";
140+
use File::Spec;
141+
# Fix for issues when runing cloc through a symlink on Windows
142+
# e.g. : it have been installed with Winget
143+
# See https://github.com/AlDanial/cloc/issues/849
144+
if ($ON_WINDOWS) {
145+
my $exec_path = abs_path($0);
146+
if (-l $0) {
147+
$exec_path = abs_path(readlink($0));
148+
}
149+
$0 = $exec_path;
150+
}
151+
139152
my $HAVE_Win32_Long_Path = 0;
140153
# Win32::LongPath is an optional dependency that when available on
141154
# Windows will be used to support reading files past the 255 char

0 commit comments

Comments
 (0)