Add Win32::LongPath to support long paths on Windows #686
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: This PR doesn't fully resolve the long path issue for Windows. The
File::Find
call will still fail when cloc is given an input with paths > 255 chars. However, theFile::Find
call can be skipped by either using a--list-file
or by using the--no-recurse
option.I added wrapper functions for most of the Win32::LongPath things that needed substituting and updated all the existing usages that should need it. I didn't add an explicit flag for enabling this, it just works based off of
$ON_WINDOWS
and$HAVE_Win32_Long_Path
for now. If you think it'd be better to have a flag to enable it, I could add that instead.The two cases where it doesn't have wrapper functions is stat/statL and opendir/opendirL. For both of those, the Win32::LongPath version returns different types that need their own handling. One of the stat usages is for
$size_in_bytes
inmake_file_list
-- I'm not sure if there was a reason stat was used over -s for this, but if there's not it could be replaced with theget_size
wrapper.While working on this I also noticed a couple issues:
sub make_file_list
where it iterates over$ra_arg_list
, the ternary to create$ul_F
was incorrectly ordered. It was$upper_lower_map{$F} ? $ON_WINDOWS : $F
but I assume it was meant to be$ON_WINDOWS ? $upper_lower_map{$F} : $F
, so I updated that while I was there.--no-recurse
. I'm not sure if it's intentional, but it only works if you run cloc from within the target dir.readdir
only returns the file names and not the whole path, so unless your cwd is in that dir, it won't find any files. I didn't change this at all, and the Win32::LongPath stuff I added there behaves the same as the existing code.Also, it's not really an issue but I was curious -- @AlDanial would you be open to adding a variant of
diff-list-file
(maybediff-list-files
?) that accepts separate list-files rather than a combined one? It seems non-trivial to decide which files should be diffed together, and I think it'd be a lot easier to let cloc handle that. I think it would be pretty easy to implement too, it should just involve adding a third case for themake_file_list
call (in theopt_diff
branch) that reads theARGV
as alist-file
and gives that tomake_file_list
. I can make another PR for that if you'd like.