Filesystem limitations of PHP’s metric tools
I’m quite heavily working with PHPMD/PDepend/PHPCPD on my local Windows machine to see, if I’ve written some mess before committing it. On some fridays I run it on the full project. Since, we added some node modules lately in our project and those modules have almost traditionally deep folder structures, I ran into a problem yesterday that is worth sharing.
As most of you know, local paths in Windows’ NTFS are structured like this: drive letter, colon, and the folder structure separated by backslashes plus one terminating null character. So for example:
C:\hello\world{NULL}
But there are some limitations to that. In most cases these default path strings can only contain 259 characters + the invisible terminating null. (Unicode versions with a special prefix can extend this value afaik). Having that in mind and the fact that node_modules have sometimes deep structures, I ended up with the following path:
C:\to\example\project\data\js\node_modules\grunt-contrib-imagemin\node_modules\image-min\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\
You don’t have to count: This string is exactly 260 characters long. Without the additional terminating null!
Now to the use-case of PDepend or PHPMD (which uses the same file traversing system as PDepend). The logic basically uses PHPs RecursiveIteratorIterator + RecursiveDirectoryIterator to walk through the filesystem. But of course, those classes are always limitted by the underlying operating system mechanics or the API it provides. Funny enough, if you try to delete this directory, even Windows tells you that he cannot put this into the recycle-bin because of its long name. It would die trying to recover files from there to their original place in the filesystem. What I couldn’t figure out yet is how this directory could be created by npm without any error. I know that there are some parts of Windows that use the standard API and some don’t. Apparently, nodes package manager found a loop-hole.
NTFS is the only common filesystem that has those limitations on the path length, luckily. Linux’ ext FS and Mac’s HFS are just having limitations on a single file name length. Hope this was still an interesting read – even for the smart people that don’t use Windows.
Cheers.
First 😉
this is a great inspiring acilrte. i am pretty much pleased with your good work. you put really very helpful information. keep it up. keep blogging. looking to reading your next post.