简体   繁体   English

Silverstripe 3.1-mkdir()问题或本地问题?

[英]Silverstripe 3.1 - mkdir() issue bug or local issue?

I seem to get this error on my local server when the site is loaded for the first time eg in the morning. 首次加载网站时,例如早上,我似乎在本地服务器上收到此错误。 Once I do a refresh it's gone... 一旦刷新,它就消失了...

I'm using silverstripe 3.1. 我正在使用silverstripe 3.1。

Is there a way to prevent this locally or is this a bug? 有没有办法在本地防止这种情况,或者这是一个错误?

Warning: mkdir(): File exists in /framework/core/manifest/ManifestCache.php on line 19

Looks like line 19 is trying to create a TEMP folder but it already exists... 似乎第19行正在尝试创建TEMP文件夹,但该文件夹已存在...

function __construct($name) {
    $this->folder = TEMP_FOLDER.'/'.$name;
    if (!is_dir($this->folder)) mkdir($this->folder);
}

Should that function check if the folder exists first eg 该功能是否应该首先检查文件夹是否存在,例如

if (!is_dir($this->folder) || !file_exists($this->folder)) mkdir($this->folder);

Seems that there exists a file with the same name as the directory. 似乎存在一个与目录同名的文件。 That's why is_dir() returns false but mkdir() fails because the file exists. 这就是为什么is_dir()返回falsemkdir()失败的原因,因为该文件存在。

You can change this to: 您可以将其更改为:

if (!file_exists($this->folder)) mkdir($this->folder);

This should work so far. 到目前为止,这应该可以工作。

However it is necessary to mention that such file existence tests are vulnerable against race conditions by design. 但是,有必要提及的是,此类文件存在测试在设计上容易受到竞争条件的影响。 That's why you need to additionally check the return value of mkdir() : 这就是为什么您需要另外检查mkdir()的返回值的原因:

if (!file_exists($this->folder)) {
    if(@mkdir($this->folder) === FALSE) {
        throw new Exception('failed to create ' . $this->folder);
    }
}

This may not being required if you (or the framework) has registered a global error handler which turns warning into exceptions, because mkdir() will throw a warning on errors. 如果您(或框架)已经注册了将警告转换为异常的全局错误处理程序,则可能不需mkdir() ,因为mkdir()会针对错误抛出警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM