Phar archive no read and write permissions with symfony filesystem

妖精的绣舞 提交于 2019-12-02 16:23:35

问题


i have created a cli app which tries to create a file with symfony 3 fileSystem component. All works fine, but if i put the app in a phar archive symfony can't write the file.

This is how i created the phar archive:

<?php
$phar = new Phar('app.phar', 0, 'app.phar');
$phar->buildFromDirectory(dirname(__FILE__) );
$phar->setStub($phar->createDefaultStub('app.php'));

The app.php call the symfony filesystem component:

<?php 

....

$this->fileSystem->dumpFile(
    'testfile.txt',
    'my test content'
);

This works fine if i execute app.php directly. But if i execute it as a .phar i get this message.

[Symfony\Component\Filesystem\Exception\IOException]  
Failed to create ".": mkdir(): File exists.

Other operations like echo working fine. In my opinion i think, that the phar archive has a problem with IO operations. But i don't unterstand whats the problem. In my php.ini is phar.readonly=Off configured.

I hope someone can give me a hint. :)


回答1:


Phar's have a different path structure, and that symfony method does dirname($filename); https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Filesystem/Filesystem.php#L679

Try defining the full path.

$path = '.';
if (!empty($pharPath = \Phar::running(false))) {
    $path = dirname($pharPath);
} 

$this->fileSystem->dumpFile(
    $path.'/testfile.txt',
    'my test content'
);


来源:https://stackoverflow.com/questions/48015539/phar-archive-no-read-and-write-permissions-with-symfony-filesystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!