-
-
Notifications
You must be signed in to change notification settings - Fork 177
F::unlink()
error handling fails when server language not English
#7086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not able to reproduce this so far. Do you have any plugins installed? |
Yes, quite some, but the error remains, even if I remove all plugins. On the other hand everything works fine again, as soon as I switch back from beta4 to beta3… I wish I could give more helpful information here, but as I said, I wasn't even able to reproduce this on the same server :/ |
I'm cc-ing @lukasbestle here. Could this be related to permissions or something else? I'm quite lost. Our code should simply ignore non-existing files when deleting. |
To be honest it's super hard to track down such issues without specific pointers to a root cause. You can help us find and fix the issue with additional debugging. It would already help a lot to narrow down either the change in Kirby that caused the regression or the custom configuration in your site code that causes it. So here are two approaches to debug this:
|
I have the same problem and maybe find something interesting : I use multilanguage. If I create a page in 1 language only and try to delete, I get the same error.
|
@SylvainAllignol this is really helpful. Thank you! |
I still cannot reproduce this properly, but I found an issue that could be related: #7097 |
Are you sure, that it actually depends on the translated files existing? Because my setup is multilingual too (DE/EN) and while trying to reproduce your conclusions I noticed something different that's enabling/disabling these errors in my setup: No matter if my content files exist only in german, only in english or in both languages and no matter what language was active when first creating them, the error when trying to delete them stayed always the same as long as I tried deleting them while using the panel in my main language (DE) – as soon as I switch to the secondary language (EN) and try deleting pages (and files) then everything works as expected! Just wanted to share this quickly, as it might help finding the root of the problem… I don't have much time left today, but will check if Bastians PR makes a difference… |
I'm sorry, but I'm too much of a Git-Noob to choose this method…
… but I will try this route again after I found out that it depends on the panel language while trying deleting something – might have missed something at my first try to reproduce a setuo with the same errors, because I didn't focus on the language settings! |
I created the same setup as @twiro - DE as default, EN as secondary. But no matter which combination of creating a page and deleting it in whichever language it does work for me without problems. |
So after having found out that those failed deletions depend on the current language in the panel I was able to reproduce this behaviour on my NGINX server (where the problems first appeared) with the following steps: Steps to reproduce these errors (on an nginx server):
Not reproducable on an apache serverI then counterchecked these steps on an Apache based server and didn't hit these errors there, so it might actually have to do something with NGINX in general or my NGINX-configuration in spcific (which worked flawlessly for all kirby versions from 4.X to 5.0.0.beta3) – I will check my configuration and test some variations as soon as possible. Language weirdnessI also started adding more languages to my setup to see how deleting content works with them, and here things start to get a little weird, because it doesn't seem like the problem comes from "de" being the main language but stems from the language itself as additional languages also behave differently:
I will perform another test run with EN as main language later… |
So after another test I can confirm that these errors don't depend on whether a language is the default language but somehow on the languages itself. I repeated the steps described in my previous post, but this time added ten languages in the following order and then tested deleting pages and files with each language selected as panel language…
Pretty weird 😲 @SylvainAllignol – is there anything you can reproduce and confirm about this? |
@twiro thank you for the extensive tests. Is the result reproducable for the languages that cannot be deleted? I somehow start thinking that this could also be some sort of filesystem cache issue on the server. |
Yep! And while doublechecking this I noticed an error in my previous test (used 'po' for polish instead of 'pl') and that led me one step further in tracing down this error – the locales seem to be the source of the trouble! After fixing the polish language code from 'po' to 'pl' the polish locale (that was empty before) got autofilled to 'pl_PL' and after that the deletion of pages/files stopped working with polish as panel language too. So I checked all locales and languages with 'simple' locales ('es','pl','pt') didn't have problems with deleting pages/files while languages with 'complex' locales ('de_DE', 'it_IT') do cause these problems – as soon as i shorten the locale deleting pages/files works again! This conclusion once more comes with an exception - english comes with the locale 'en_US' and does not cause any trouble… |
@twiro that's a great next step to debug this. Could you send me the filename in site/languages of a language that cannot be deleted and also the content of the language.php file? |
And maybe too far fetched, but the created content files are named |
Just to be clear and avoid misunderstandings – the languages / language files can always be deleted. The issue this is all about is that (in my nginx environment and after the update to beta4) every page and file in the panel can no more be deleted when the panel is set to a language that uses a locale that follows the As soon as I manually edit the locale of an affected language and reduce it to The language files itself are properly named
Should I still send the files…? Or would a short video help maybe? I could also give you panel access to a test installation with this behavior.
Properly named As this issue affects all pages and files (created prior to the update to beta4 and all named properly) It doesn't look like it has to do something with wrong naming… |
@twiro We are not asking for all those details implying you named something wrong. We just haven't been able to replicate this problem ourselves, so we are asking for all the details to see if in our attempts to recreate it, we're doing anything differently form you that might help to replicate it. :) |
@distantnative no problem :) Didn't even understand it that way as I thought you meant Kirby could somehow use the full locale for the naming of files ;) |
I tested a few more languages/locales this morning, and the results don't make things any easier to grasp… It's not that "en_US" is the only longer locale that doesn't cause problems, there's actually quite a few of them (e.g. Albaninan, Japanese, Ukrainian, Vietnames)! But I really don't see any pattern in this :/ The only thing that seems to be consistent is, that if I (however) remove the underscore (e.g. "de-DE" instead of "de_DE") every locale that caused deletion-errors before immediately stops throwing errors. So isn't the main question now, what the locale of the current panel language actually has to do with deleting pages and files in the panel and what has changed inbetween beta3 and beta4 that could make some locales with an underscore causing these kind of errors shown in the screenshot in my first posting?This is actually as far as I can dig, I don't know what more I could test now… I guess it would be really helpful if someone could confirm this behavior, so maybe @SylvainAllignol could try to also test deleting of pages/files with different panel languages/locales and see if he can confirm the locales beeing involved here… |
I couldn't reproduce the issue either on my local Herd setup. |
Didn't really do it the git way, but I started testing different steps of the repository between beta3 and beta4 and could track down the error to commit d0e671a Before this commit everything works as expected, after that commit the weird deleting errors show up! I hope this helps in getting closer to a solution… |
@twiro Maybe you can share a kit with us for the issue so we can reproduce it. I tried again locally, but I couldn't reproduce the issue. I put it on my Apache server, and it still seems to works fine. It seems like this issue is server related. I just wonder that can you reproduce this issue on any nginx machine? |
Alright… I spent half the day digging further into this issue and I think I finally know what's going on and how this issue is related to languages/locales. The crazy thing is that my first screenshot already shows the crucial detail - in the form of the german-language error message "Datei oder Verzeichnis nicht gefunden". But for a better understanding let's start with how I got there… After having found the commit that started this issues I started my search at these new lines in the delete-function in kirby/src/Content/Version.php: 1) kirby/src/Content/Version.phpif ($language === '*') {
foreach (Languages::ensure() as $language) {
$this->delete($language);
}
return;
} This calls the delete-function for every panel language, no matter if the version has a file in that language or not. It then passes version and language to the delete-function of the model ( 2) kirby/src/Content/PlainTextStorage.php/**
* Deletes an existing version in an idempotent way if it was already deleted
*/
public function delete(VersionId $versionId, Language $language): void
{
$contentFile = $this->contentFile($versionId, $language);
// @codeCoverageIgnoreStart
if (F::unlink($contentFile) !== true) {
throw new Exception(message: 'Could not delete content file');
}
// @codeCoverageIgnoreEnd
… This confused me a little bit, as this function is described as deleting an ‘existing version’, but since the Beta4 version it is called for both the ‘latest’ and ‘changes’ versions in every available panel language - regardless of whether files exist for these versions or languages. The unlink function is therefore called for a whole series of non-existent files, especially in configurations with many languages (and translations that have not been entered consistently). But this function also drew my attention to the error messages, because they didn't have the wording "Could not delete content file", but "Datei oder Verzeichnis nicht gefunden" if I used german as panel language or alternatively "Aucun fichier ou dossier de ce type" if I used French as the panel language, for example. 3) kirby/src/Filesystem/F.phpSo I had a look into the unlink-function in kirby/src/Filesystem/F.php and stumbled upon this english error message that was used in a string-comparison: public static function unlink(string $file): bool
{
return Helpers::handleErrors(
fn (): bool => unlink($file),
// if the file or link was already deleted (race condition),
fn (int $errno, string $errstr): bool => Str::endsWith($errstr, 'No such file or directory'),
// consider it a success
true
);
} And this looked like the source of all theses troubles… "Datei oder Verzeichnis nicht gefunden" is not the same as "No such file or directory"! 4) kirby/src/CMS/Helpers.phpI then jumped into Helpers::handleErrors and included a little log-function, that wrote the values of the $errstr to my php-logfile and this is the (at this moment no more really suprising) result of my logs: 5.A) Test Results with full locales
5.B) Test Results with stripped localesThe last thing I checked was if the error message actually changes if I remove the second part of the locales and as expected it does:
ConclusionI haven't investigated further for today and I don't know if the translated error messages have anything to do with the my Server, PHP- or NGINX-settings, but regardless, the problem should probably be best fixed directly with a more reliable solution in the unlink-function in kirby/src/Filesystem/F.php, right? |
@twiro that's great debugging, thanks for getting to the bottom of this! Indeed we will need a more reliable way to check for the error type if the error messages not always are in English. Pinging @lukasbestle here as well. |
F::unlink()
error handling fails when server language not English
@twiro Thank you very much for your research and detailed explanations. I didn't make the connection between the change to However what I'm really confused by is that your PHP installation localizes warnings in the first place (and then only to some locales). I have looked into the PHP source code and found that they have a unit test for the English warning and hardcode that in all sorts of places. I can't get my local installation to localize that warning, even though it is compiled with I have an idea though. You wrote that the warning message depends on the locale. Could you please test what output the following script creates on your affected machine: setlocale(LC_MESSAGES, 'de_DE');
unlink('this-file-does-not-exist');
setlocale(LC_MESSAGES, 'C');
unlink('this-file-does-not-exist'); |
indeed quite strange! Especially since translated error messages would only make sense - if at all - if they were dependent on the account/system language and not on the panel/content language (I have just realised that this point could also be misunderstood in my previous comments - by ‘panel language’ I have always meant the languages of the contents (that can be managed & changed in the panel) and not the language of the Kirby interface (that can be changed in the account settings)). I'm using the default PHP settings from my hoster (Timme) and haven't had any similar issues, but if this is something that shouldn't be happening and the PHP settings are to blame, I'll try to contact them and ask if this could be avoided by using different default PHP settings on their end.
Just checked this (with a little varied file names) and the result is the following:
|
@twiro thank you so much for all your help. We finally seem to have a solution :) |
Quick reply as I'm currently not in the office: Everything is alright, the hosting provider does not need to change anything. It's a bug in Kirby and the result of your test confirmed it. We are working on a solution. |
Longer reply: It turns out to be expected that error and warning messages can be localized by PHP. This is handled by the The So TL;DR: We didn't realize that the warning can be localized at all because it wasn't localized in our local setups. With Bastian's PR, we fix it by always using the default/unlocalized |
Thank you :) I'm glad the investigations payed off and I could help solving this just in time for the release of RC1!
Thank you for these explanations, makes more sense now (and I'm also relieved that there's nothing wrong with the settings on my server). |
Description
I'm currently working on a new website that was running just fine on 5.0.0-beta.3, but now has some serious issues in the panel after updating to the latest beta. I could track down the one linked above (failing page creation), but am pretty stuck with another one:
Deleting pages and files fails in all cases and always returns this kind of error:
unlink(/var/www/clients/clientXX/webXX/web/content/2_about/_changes/ocean.jpg.de.txt): Datei oder Verzeichnis nicht gefunden
unlink(/var/www/clients/clientXX/webXX/web/content/2_about/testkapitel/_changes/kapitel.de.txt): Datei oder Verzeichnis nicht gefunden
I guess it has to do something with the new versions-feature and the "
_changes
"-folder not existing, but I'm not sure, as I'm not able to reproduce this behaviour myself.I tried to track it down by rebuilding the whole site step by step under a different domain up to the moment, where I had a complete clone of the website running there (including the complete content), but everything kept working fine, including the deleting of files and pages.
I then copied my working clone from Domain B and replaced my original code of Domain A (fixing the configs/urls for sure) only to face the error again… no deleting of pages or files possible.
Both domains run on the same server (Timme/Nginx) with exactly the same configuration.
Pretty strange, but even if I can't reproduce it and it might be somehow releated to my specific domain/server-setup I thought I'd post a bug report nonetheless, as this errors are a direct result of updating to the latest beta and we didn't face them before (with the same server/domain-setup).
Screenshot
Your setup
Kirby Version: 5.0.0.beta4
The text was updated successfully, but these errors were encountered: