I am getting the error and no XML output for a CLOC run on the OSS project mojarra. The error is:
Can't cd to p:\analysis\downloads\481 [JavaServer Faces]\repositories/481727/MOJARRA_2_1X_ROLLING/test/agnostic/vdl/facelets/faces-config-extension/html5/src/test/java/com/sun/faces/test/agnostic/vdl/facelets/faces_config_extension/html5../../../../../../../../../../../../../.. at PERL2EXE_STORAGE/File/Find.pm line 940.
This problem in similar form occurs for other projects as well.
I am using cloc-1.60.exe on Windows 7 64bit, NTFS file system, with the following command line:
p:\analysis\binaries\cloc\cloc-1.60.exe --xml --by-file-by-lang --report-file p:\analysis\downloads\481 [JavaServer Faces]\loc_project_xml_481.xml p:\analysis\downloads\481 [JavaServer Faces]\repositories
TO REPRODUCE:
If you need any additional info, let me know.
Anonymous
Submitter is me, forgot to log in.
I did the following on a Linux machine using the current development snapshot of cloc:
There were no issues; report file is attached. Tomorrow I'll try on a Windows machine to see if I can duplicate the problem.
Thanks for investigating; I am interested to see whether this is a Windows issue!
Update: I just tried installing Strawberry Perl and running "perl cloc-1.60.pl" instead of cloc-1.60.exe. The error message differs slightly but points to the same problem:
:(
I just finished a successful run on Windows. Here's my theory on why your run fails: the target directory path name, "p:\analysis\downloads\481 [JavaServer Faces]\repositories/481727" has open and close brackets that confuse the File::Find module where the error occurs. (As you may know, in Perl, open/close brackets define a character class for regular expressions.)
To test that theory, copy the Mojarra code to another directory name that is as vanilla as they come, like c:\tmp, then run cloc against the source at that location.
Hi Al,
Some more experiments from my side have revealed the following issues. First, shortening the path works:
However, adding [] to the path shows no difference, so this does not seem to be the issue:
Then again, LENGHTENING the path leads to the issue:
So, I conclude, long file names are the issue on Windows. Can you reproduce?
...previous anonymous post was me again, forgetting to log in. Grrr. Apparently needs moderator approval this time ;-)
Last edit: Phil Mayer 2014-03-26
Yes, it is a file path length issue on Windows. (The same long path I tried on Linux on an NFS file system worked, but I'm sure there's a point where it, too, breaks.)
Update with a possibly related error:
I've got the same issue due to the way npm handles dependencies https://github.com/npm/npm/issues/3697
More annoyingly the trouble occurs on a folder that has been specified as ignored
The path "D:\ccnet\projects\Isogeo.App\ContinuousBuild\work/node_modules/grunt-contrib-imagemin/node_modules/gifsicle/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib" has 259 characters, close to the maximum of 260 supported by Windows (ref http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath). If the lib directory at the end has anything in it, the 260 characters will be exceeded.
I haven't proven it but I think there's a problem even sooner, after 255 just characters, with Perl's File::Find module.
My recommendation is to cd into the "D:\ccnet\projects\Isogeo.App\ContinuousBuild\work" then pass cloc the current directory, ".", and see if that shortens the path sufficiently.
Finally, regarding the ignored directory, the ignore step happens after the directory name is determined. In other words, the code can't ignore a directory until it knows its full name, and the failure happens then.
I understand the path is way too long for Windows to handle, but in this case CLOC was instructed to exclude all paths containing node_modules so there is no logical need for it to go that deep in the folder hierarchy (the first occurence happens way before the 260 characters limit).
how about allowing CLOC to use the "\?\" prefix (cf. http://msdn.microsoft.com/en-us/library/Aa365247)? It would require using "\" instead of "/" as a path delimiters though.
maybe the folder analysis algorithm could be improved so that it would not have to analyse subfolders of an excluded one? This alone would solve my particular problem.
OK I understand your point. cloc actually already does (that is, should do) what you describe in your second bullet point: if it encounters the name of an excluded directory, it stops its traversal and continues to the next directory returned by File::Find.
The code in question (source at http://sourceforge.net/p/cloc/code/HEAD/tree/trunk/cloc) begins at line 3047:
One problem has to do how File::Find presents path separators. The regex at line 3047 will only skip the directory if it is enclosed by /'s. If on Windows File::Find returns the path with \ separators then I'll need to tweak the regex. (My dev machine is Linux but I'll have access to Windows later in the week to see what's going on there.)
Incidentally, if you run cloc with the verbose level at 6 or greater (cloc -v 6 ...), you can follow exactly which directory is being investigated; look for lines that begin with "files(". Excluded directories shouldn't appear. Also helpful in this case is running with "--ignored=ignored.txt". The resulting ignored.txt file should contain file names which were in directories that were excluded.
If you can tell me whether or not excluded directories appear with a -v 6 run that would be helpful. If they do appear, the issue is with the path separators. If they don't appear, the issue is with File::Find and I'll need to investigate ways to prune the search tree (there is an option File::Find::prune) to terminate unwanted descents.
The topmost folder that should be excluded appears in the output (files(D:\ccnet\projects\Isogeo.App\ContinuousBuild\work/node_modules) zero size). This is the last line that appears in the output before the error above occurs on a subfolder.
The ignored files does not seem to be generated. Must be because of the exception?
Right, the ignored file isn't written until the (successful) end of the run.
In any case, I now know how to fix the problem once and for all. Got a good tip from http://stackoverflow.com/questions/12334037/perl-how-to-stop-filefind-entering-directory-recursively on calling a preprocessor with File::Find to prune directories before descending into them. I'll implement the fix this weekend, in the mean time will reopen this as a bug.
fixed with svn commit 380
v1.62 released