Skip to content

Loading…

DCOM-234: Cache file fails on Windows - name too long #542

Closed
doctrinebot opened this Issue · 7 comments

6 participants

@doctrinebot

Jira issue originally created by user mattsnowboard:

The filename component of the FileCache is unbounded. It is possible to attempt to create files that are too long for the Windows filesystem. This causes an exception.

Example from a Symfony CMF/PHPCR project:

fileput_contents(D:\web_workspace\study\app\cache\dev\doctrine\cache\71d059fe39968db8\3e485dbb27419897\dfb24337887ff42c\a7b85c70bfefa781\nodes[nodes weak references cmsprogrampagesThe Summer ProgramThe Calendar 5 weeks for all Europe, routeContent, default][49].doctrinecache.data): failed to open stream: Invalid argument in D:\webworkspace\study\vendor\doctrine\cache\lib\Doctrine\Common\Cache\FilesystemCache.php line 111

In this case, the ID was
"nodes[nodes weak references cmsprogrampagesThe Summer ProgramThe Calendar 5 weeks for all Europe, routeContent, default][49].doctrinecache.data"

That refers to a phpcr node:
cms/program/pages/The Summer Program/The Calendar 5 weeks for all Europe

Attempting to manually create that file in windows explorer shows that it is trunacted to
"nodes[nodes weak references cmsprogrampagesThe Summer ProgramThe Calendar 5 weeks for all Europe, routeContent, default][49].do" (128 characters)

Shouldn't the ID be truncated so this doesn't happen? Should this be fixed here or in the phpcr that is creating the long ID to begin with?

@doctrinebot

Comment created by mwe:

This is really an issue on windows. The Maximum path length is 260. (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath)

FileCache.php:
line 117:  // This ensures that the filename is unique and that there are no invalid chars in it.       
line 118: if ('' === $id || strlen($id ) > ((255 - strlen($this->extension)) / 2)) {

On windows, the directory has to be included:
with the following patch work fine. the 4 extra characters are for DIRECTORY_SEPARATOR (2 times) and for substr($hash, 0, 2):

line 117: if ('' === $id || strlen($id . $this->getDirectory() ) + 4 > ((255 - strlen($this->extension)) / 2)) {

I'v updated to Symfony 2.8 and ran in this problem.

@doctrinebot

Comment created by spicimedved:

Yes, I see the same problem on my Windows 10 notebook. I've just updated to Symfony 2.8 and Symfony is complaining that the cached annotation files connot be loaded.

See also this question http://stackoverflow.com/questions/30783052/failed-to-open-stream-while-compiling-cache-for-dev-environment

I can provide more detailed information if needed

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@crayner

Agreed. Windows 10 environment also running into issues clearing the cache.

Failed to remove directory "F:\Dropbox\Symfony\Busybee\var\cache\dev_old\annotations\9f".

File Names like: 5b53796d666f6e795c42756e646c655c57656250726f66696c657242756e646c655c436f6e74726f6c6c65725c50726f66696c6572436f6e74726f6c6c657223736561726368426172416374696f6e405b416e6e6f745d5d5b315d.doctrinecache.data

Looking forward to a fix. Symfony 3.

@ohvitorino

I'm suffering from the same problem.

The filenames within the annotation folders are too long for PHP+Windows. Doctrine will no delete the files because for PHP the files don't exist. After that, the directory cannot be remove because it's not empty.
I see two possible solutions: either the Dotrine cache filenames need to be shorter OR the remove() function the Symfony Filesystem component has to be improved to deal with these situations specifically on Windows.

In the meantime, is there any known workaround for this?

@stof
Doctrine member

The solution is for Doctrine IMO (and there is already a PR for that IIRC)

@stof
Doctrine member

Actually, doctrine/cache#107 has been merged already

@stof stof closed this
@beberlei beberlei was unassigned by Ocramius
@stof stof was assigned by Ocramius
@Ocramius Ocramius added the Invalid label
@ohvitorino

Hi @stof, thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.