【问题标题】:Symfony 4 - Failed to save key...of type array: touch(): Utime failed: Operation not permittedSymfony 4 - 无法保存密钥...类型数组:触摸():Utime失败:不允许操作
【发布时间】:2019-12-04 22:42:01
【问题描述】:

我在使用 Symfony 4.3.2 运行的网页上发现此错误

Failed to save key "xxxx" of type array: touch(): Utime failed: Operation not permitted

但我不知道它来自哪里,所以如果有人有一点线索,我就是买家。 我不知道它是否有帮助,但我在 Windows 10 上使用 ubuntu

[2019-07-26 16:04:09] php.DEBUG: Warning: chmod(): Operation not permitted {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\SilencedErrorContext: {\"severity\":2,\"file\":\"/devdir/myProject/vendor/symfony/filesystem/Filesystem.php\",\"line\":696,\"trace\":[{\"file\":\"/devdir/myProject/vendor/symfony/config/ResourceCheckerConfigCache.php\",\"line\":124,\"function\":\"dumpFile\",\"class\":\"Symfony\\\\Component\\\\Filesystem\\\\Filesystem\",\"type\":\"->\"}],\"count\":1})"} []
[2019-07-26 16:04:09] php.DEBUG: Warning: chmod(): Operation not permitted {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\SilencedErrorContext: {\"severity\":2,\"file\":\"/devdir/myProject/vendor/symfony/filesystem/Filesystem.php\",\"line\":202,\"trace\":[{\"file\":\"/devdir/myProject/vendor/symfony/config/ResourceCheckerConfigCache.php\",\"line\":126,\"function\":\"chmod\",\"class\":\"Symfony\\\\Component\\\\Filesystem\\\\Filesystem\",\"type\":\"->\"}],\"count\":1})"} []
[2019-07-26 16:04:09] request.INFO: Matched route "fos_js_routing_js". {"route":"fos_js_routing_js","route_parameters":{"_route":"fos_js_routing_js","_controller":"fos_js_routing.controller::indexAction","_format":"js"},"request_uri":"http://myProject.local/js/routing?callback=fos.Router.setData","method":"GET"} []
[2019-07-26 16:04:09] cache.WARNING: Failed to save key "%5BFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:09] cache.WARNING: Failed to save key "%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:09] cache.WARNING: Failed to save key "%5BFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:09] cache.WARNING: Failed to save key "%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:20] request.INFO: Matched route "fos_js_routing_js". {"route":"fos_js_routing_js","route_parameters":{"_route":"fos_js_routing_js","_controller":"fos_js_routing.controller::indexAction","_format":"js"},"request_uri":"http://myProject.local/js/routing?callback=fos.Router.setData","method":"GET"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5BFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5BFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DFOS%5CJsRoutingBundle%5CController%5CController%23indexAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_route":"_wdt","_controller":"web_profiler.controller.profiler::toolbarAction","token":"a0f28c"},"request_uri":"http://myProject.local/_wdt/a0f28c","method":"GET"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5BSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5B%5BC%5DSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5BSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%23toolbarAction%5D%5B1%5D" of type array: touch(): Utime failed: Operation not permitted {"key":"%5BSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%23toolbarAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []
[2019-07-26 16:04:21] cache.WARNING: Failed to save key "%5B%5BC%5DSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%23toolbarAction%5D%5B1%5D" of type integer: touch(): Utime failed: Operation not permitted {"key":"%5B%5BC%5DSymfony%5CBundle%5CWebProfilerBundle%5CController%5CProfilerController%23toolbarAction%5D%5B1%5D","exception":"[object] (ErrorException(code: 0): touch(): Utime failed: Operation not permitted at /devdir/myProject/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:95)"} []

【问题讨论】:

  • this 看起来很相似
  • 是的,但是答案不太适合我的情况,如果有人有相关的解决方案,将受到欢迎!
  • 你在使用 vagrant 吗?
  • “我在 Windows 10 上使用 ubuntu”这里没有流浪者
  • 您找到解决方案了吗?

标签: php symfony caching


【解决方案1】:

如果您碰巧使用 FAT/FAT32 或其他时间戳范围受到严格限制的文件系统,那么该警告是意料之中的。

Symfony 的 FilesystemCommonTrait::write() 方法使用 unix 时间戳 0 调用 touch() 函数来强制缓存内容过期。 Unix 时间戳 0 代表 1970-01-01 日期。根据维基百科,在 FAT 文件系统中,允许的时间戳范围是 1980-01-01 到 2099-12-31。所以touch()函数失败并发出警告。

解决方法是在第 80 行附近修改 FilesystemCommonTrait::write() 方法。

找线:

if (null !== $expiresAt) {
    touch($this->tmp, $expiresAt);
}

在这些行之前插入:

if (0 === $expiresAt) {
    $expiresAt = time() - 1;
}

这应该通过立即使缓存内容过期来实现几乎相同的结果,但不使用无效的文件系统时间戳。

或者,更改文件系统类型。

【讨论】:

    【解决方案2】:

    今天,为了避免在每次安装此依赖项时重做此操作,我们可以使用一个非常简单的技巧。这是一个简单的patch manager。它将本地或远程文件中的补丁应用到 composer 所需的任何包中。

    安装:

    composer require cweagans/composer-patches
    

    创建补丁:(对我来说:Patches/filesystemtrait_touch.patch)

    --- a/vendor/symfony/cache/Traits/FilesystemCommonTrait.php 2021-11-23 19:51:45.000000000 +0100
    +++ b/vendor/symfony/cache/Traits/FilesystemCommonTrait.php 2021-12-17 09:07:46.428495909 +0100
    
    @@ -108,6 +108,10 @@
                 fwrite($h, $data);
                 fclose($h);
    
    +            if (0 === $expiresAt) {
    +                $expiresAt = time() - 1;
    +            }
    +
                 if (null !== $expiresAt) {
                     touch($this->tmp, $expiresAt);
                 }
    

    修改作曲家json:

     {
      "require": {
        // ...
      },
      "extra": {
        "symfony": {
          "allow-contrib": false,
          "require": "5.4.*"
        },
        "patches": {
          "symfony/cache": {
            "modify the FilesystemCommonTrait": "./Patches/filesystemtrait_touch.patch"
          }
        },
        "composer-exit-on-patch-failure": true
      }
    }
    

    然后你可以尝试删除vendor/symfony/cache中的组件并运行更新命令,补丁会自动应用

    root#/data/www/myproject: composer update
    Gathering patches for root package.
    Loading composer repositories with package information
    Restricting packages listed in "symfony/symfony" to "5.4.*"
    Updating dependencies
    Nothing to modify in lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
    Gathering patches for root package.
    Gathering patches for dependencies. This might take a minute.
      - Installing symfony/cache (v5.4.0): Extracting archive
      - Applying patches for symfony/cache
        ./Patches/filesystemtrait_touch.patch (modify the FilesystemCommonTrait)
    
    Generating autoload files
    // ...
    

    希望这个小技巧对你有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      • 2020-08-26
      • 2011-11-17
      • 2019-01-25
      相关资源
      最近更新 更多