-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix for systems where the RecursiveDirectoryIterator does not behave as specified #510
Conversation
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Enable pull request feddback Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: CaCO3 <caco3@ruinelli.ch> Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: CaCO3 <caco@ruinelli.ch>
Signed-off-by: CaCO3 <caco@ruinelli.ch>
8ca32a3
to
99dedce
Compare
f44df1a
to
f2ec935
Compare
@solracsf @MorrisJobke @nickvergessen @blizzz @come-nc Whoever is in charge, please review and provide further information how to pass all checks. |
e868147
to
b1e0df8
Compare
Hello, Thank you for the fix! I tried to reproduce issue php/php-src#509 but failed. /**
* Moves the specified files except the excluded elements to the correct position
*
* @throws \Exception
*/
private function moveWithExclusions(string $dataLocation, array $excludedElements): void {
// Build file list first, so the renames won't mess with it
/** @var array<string, \SplFileInfo> */
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator($dataLocation), true);
foreach ($fileList as $path => $fileInfo) {
$fileName = explode($dataLocation, $path)[1];
$folderStructure = explode('/', $fileName, -1); Does it fix the issue for you? I think it will be faster if we avoid disk accesses. |
Following #509 (comment) the actual issue seems that the recursive directory iterator does not work properly on FreeBSD. Given that we don't list FreeBSD as supported operating system https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html I suggest closing this pull request and the related issue. A user can always use the manual update. |
@caco3 mentioned here #508 (comment) that recursiveDelete works. Lines 776 to 816 in 55eca48
A possible explanation could be that we iterator over the iterator before changing the file system. |
I created a ticket on my hoster so they can investigate this issue. Usually they are quite quick and supportive.
Please do not do this!
Which a real pain since all apps have to be installed again separately!
Yes, this works as well. I updated the PR accordingly. Under which OS did you test it? |
56a4504
to
5500d71
Compare
Lines 285 to 298 in 55eca48
As explained before, the iterator will return the files before the directory and therefore rmdir will work fine.
Upgrade guide: https://docs.nextcloud.com/server/latest/admin_manual/maintenance/manual_upgrade.html Configure a custom app directory to make the upgrade easier: https://docs.nextcloud.com/server/latest/admin_manual/apps_management.html#using-custom-app-directories |
Dear all Thanks for your valuable comments. I modified the PR as following:
This way I was successfully able to update my Nextcloud.
|
Looking on all usage of in Nextcloud (https://github.com/search?q=org%3Anextcloud+RecursiveIteratorIterator%3A%3ACHILD_FIRST&type=code), there are some other places, where the Note worthy also is following comment: So it seems I am not the first one who had issues with the |
Looks like that's originally from a nearly 10 year ago OC issue here: owncloud/core#8376 |
@Altahrim What am I supposed to do for the failing "same code base" check? |
commit results from |
But is In case I have to run it locally: I can't due to missing dependencies. |
I like the changes in the current form as this strategy is reasonable, simple and indeed safer to get the list of files first. An issue with the memory footprint could theoretically be the data directory. While it should not lie within the nextcloud root, it might be in reality, and we don't control the size or contents. The are some slight changes in early exceptions, but it does not change anything in general. ✔️ Especially because the updater is a sensitive part and could leave users stranded if there are issues, a lack of surprises is being fancied ;) |
The workflow is currently only a checker, it does not commit and push its results. |
1d125b5
to
b96506b
Compare
The changes to I cannot reproduce the other changes with your branch and Composer version 2.6.5 2023-10-06 10:11:52. Are you familiar with git enough to clean up the git history a bit?
|
I have to dig into how to cleanup the history. Can you first solve the conflict with the |
That's also fine.
They were changes in master in the meantime. |
f302194
to
086a1ed
Compare
…to fix-delete-step
As backup, the latest diff: 510.diff.txt |
sorry for the mess 😒 I made a new PR with a clean history -> #515 |
Yes, my Ubuntu still had an older version :( |
This should no longer be an issue after #507 |
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! |
superseded by #515
This PR solves the failing updates due to issues on removing the old files and copying the new files.
See #158 for details.
And it also solves the issue some systems have when modifying a directory while iterating through it, see #509 for details.
TL;DR
On some servers (notable
FreeBSD 12.4
on hostspoint.ch), the updater tries tormdir()
non-empty folders. This is not supported on PHP. The updater already has a function to recursively delete (recursiveDelete()
), how ever it is not used consistently.Additionally, the iterator gets gets messed up in the move step when modifying the directories. Thus we copy() instead of rename() and remove the whole folders/files afterwards in a separate iteration.
Scroll down for the fix.
Issue
Updater fails to delete old files:
updater log on first deletion failure:
The general issue seems to be that rmdir only is able to delete empty folders.
The first time the issue occurs for me is on deleting the
lib/l10n
folder.Looking on the folder, it clearly is not empty at that time:
> ls af.json az.js br.js el.js es_AR.json es_EC.json es_PR.json fo.js gd.json hy.js id.json km.js lb.js mk.json nl.json pt_BR.js si.js th.js vi.json an.js az.json bs.js el.json es_CL.js es_HN.json es_UY.json fo.json he.js hy.json is.json kn.js lb.json ms_MY.js oc.js pt_BR.json sk.js th.json zh_CN.js ar.js be.js cs.json eo.js es_CL.json es_MX.json et_EE.json fr.js hr.json ia.js it.js kn.json lo.json nb.json pl.js pt_PT.js sq.js tk.json zh_TW.js ast.js bg.json da.js eo.json es_CO.js es_NI.json eu.json fr.json hu.js ia.json ja.js ko.js lt_LT.json ne.json pl.json pt_PT.json sq.json ur_PK.js ast.json bn_BD.js de_DE.json es_419.js es_DO.js es_PE.js fi.json gd.js hu.json id.js ka_GE.js ko.json lv.json nl.js ps.js sc.json ta.json ur_PK.json
Note that it still contains 93 files. Odly, originally it contained 200 files, so some successed to get deleted...
Fix
rmdir()
andunlink()
.Using that fix, I am successful to update Nextcloud
27.0.0
to the latest (currently27.1.2
).