From 0d7373a85288411e7b2889471422c93d486f25d0 Mon Sep 17 00:00:00 2001 From: EDM115 Date: Sun, 25 Aug 2024 12:33:42 +0200 Subject: [PATCH 1/2] fix: works when ran through a symlink closes https://github.com/AlDanial/cloc/issues/849 --- cloc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cloc b/cloc index 3c730cff..f5aa620d 100755 --- a/cloc +++ b/cloc @@ -136,6 +136,19 @@ if ($ON_WINDOWS and $ENV{'SHELL'}) { } } +use Cwd "abs_path"; +use File::Spec; +my $exec_path = abs_path($0); +# Fix for issues when runing cloc through a symlink on Windows +# e.g. : it have been installed with Winget +# See https://github.com/AlDanial/cloc/issues/849 +if ($ON_WINDOWS) { + if (-l $0) { + $exec_path = abs_path(readlink($0)); + } + $0 = $exec_path; +} + my $HAVE_Win32_Long_Path = 0; # Win32::LongPath is an optional dependency that when available on # Windows will be used to support reading files past the 255 char From 237c5e34f147e121cb1eb2fb8404f8045b18164e Mon Sep 17 00:00:00 2001 From: EDM115 Date: Sun, 25 Aug 2024 17:37:24 +0200 Subject: [PATCH 2/2] fix: see #850 - also edited the file in Unix dir as I believe they shouldn't be different - edited Unix/AUTHORS --- Unix/AUTHORS | 3 ++- Unix/cloc | 13 +++++++++++++ cloc | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Unix/AUTHORS b/Unix/AUTHORS index 8e6413fe..83423920 100644 --- a/Unix/AUTHORS +++ b/Unix/AUTHORS @@ -31,4 +31,5 @@ https://github.com/Inventitech https://github.com/zhangzqs https://github.com/drkameleon https://github.com/jackos -https://github.com/Aerek-Yasa \ No newline at end of file +https://github.com/Aerek-Yasa +https://github.com/EDM115 \ No newline at end of file diff --git a/Unix/cloc b/Unix/cloc index 7eb1653e..2c124400 100755 --- a/Unix/cloc +++ b/Unix/cloc @@ -111,6 +111,19 @@ if ($ON_WINDOWS and $ENV{'SHELL'}) { } } +use Cwd "abs_path"; +use File::Spec; +# Fix for issues when runing cloc through a symlink on Windows +# e.g. : it have been installed with Winget +# See https://github.com/AlDanial/cloc/issues/849 +if ($ON_WINDOWS) { + my $exec_path = abs_path($0); + if (-l $0) { + $exec_path = abs_path(readlink($0)); + } + $0 = $exec_path; +} + my $HAVE_Win32_Long_Path = 0; # Win32::LongPath is an optional dependency that when available on # Windows will be used to support reading files past the 255 char diff --git a/cloc b/cloc index f5aa620d..5304b4e3 100755 --- a/cloc +++ b/cloc @@ -138,11 +138,11 @@ if ($ON_WINDOWS and $ENV{'SHELL'}) { use Cwd "abs_path"; use File::Spec; -my $exec_path = abs_path($0); # Fix for issues when runing cloc through a symlink on Windows # e.g. : it have been installed with Winget # See https://github.com/AlDanial/cloc/issues/849 if ($ON_WINDOWS) { + my $exec_path = abs_path($0); if (-l $0) { $exec_path = abs_path(readlink($0)); }