如何修复NextCloud找不到文件报错?
- By : Will
- Category : Cloud storage
1 前言
一个问题,一篇文章,一出故事。
老板访问NextCloud已删除文件的分享链接,链接范例如下,
https://nextcloud.cmdschool.org/index.php/s/grqtC3nzaNSZ17Qz4Dq8
页面有如下错误提示,
笔者使用如下命令修改NextCloud的配置,
vim /var/www/nextcloud/config/config.php
使用如下配置重新定义程序的日志级别为调试模式,
'loglevel' => 0
然后查看后台发现如下错误提示,
Exception: Call to a member function isReadable() on string in file '/var/www/nextcloud/apps/files_sharing/lib/Controller/ShareController.php' line 318 /var/www/nextcloud/lib/private/AppFramework/App.php - line 164: OC\AppFramework\Http\Dispatcher->dispatch(OCA\Files_Sh ... {}, "showShare") /var/www/nextcloud/lib/private/Route/Router.php - line 304: OC\AppFramework\App::main("OCA\\Files_ ... r", "showShare", OC\AppFramew ... {}, { token: "b7 ... "}) /var/www/nextcloud/lib/base.php - line 1017: OC\Route\Router->match("/s/grqtC3nzaNSZ17Qz4Dq8") /var/www/nextcloud/index.php - line 36: OC::handleRequest() 造成的原因是 Error: Call to a member function isReadable() on string /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareController.php - line 343: OCA\Files_Sharing\Controller\ShareController->validateShare(OC\Share20\Share {}) /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 217: OCA\Files_Sharing\Controller\ShareController->showShare("") /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 126: OC\AppFramework\Http\Dispatcher->executeController(OCA\Files_Sh ... {}, "showShare") /var/www/nextcloud/lib/private/AppFramework/App.php - line 164: OC\AppFramework\Http\Dispatcher->dispatch(OCA\Files_Sh ... {}, "showShare") /var/www/nextcloud/lib/private/Route/Router.php - line 304: OC\AppFramework\App::main("OCA\\Files_ ... r", "showShare", OC\AppFramew ... {}, { token: "b7 ... "}) /var/www/nextcloud/lib/base.php - line 1017: OC\Route\Router->match("/s/grqtC3nzaNSZ17Qz4Dq8") /var/www/nextcloud/index.php - line 36: OC::handleRequest()
2 最佳实践
2.1 定位错误代码
vim /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareController.php
根据日志的提示定位到318行的代码,
return $share->getNode()->isReadable() && $share->getNode()->isShareable();
注:改行可以找到错误日志中提到的“isReadable()”函数
2.2 调试错误代码
vim /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareController.php
错误行加入如下代码,
var_dump($share->getNode()); die; return $share->getNode()->isReadable() && $share->getNode()->isShareable();
再次访问错误链接,
https://nextcloud.cmdschool.org/index.php/s/grqtC3nzaNSZ17Qz4Dq8
可见如下提示,
string(0) ""
注:由于文件已经删除,返回的对象为空,所以报错
2.3 修复错误代码
vim /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareController.php
加入如下代码,
if (empty($share->getNode())) { return false; } return $share->getNode()->isReadable() && $share->getNode()->isShareable();
注:判断如果获取到的文件或目录对象为空,则返回“false”
2.4 测试错误代码
https://nextcloud.cmdschool.org/index.php/s/grqtC3nzaNSZ17Qz4Dq8
参阅文档
=====================
https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/logging_configuration.html
没有评论