Skip to content
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

diverse mirror fixes #552

Merged
merged 8 commits into from
May 10, 2020
Merged

diverse mirror fixes #552

merged 8 commits into from
May 10, 2020

Conversation

Garfonso
Copy link
Contributor

@Garfonso Garfonso commented May 10, 2020

This is an extended version of #550 - like #550 this should also fix #551
I did some more fixes and cleanup in mirror.js. Those are not as critical and are not really complete, yet, but I lost time to finish them. So maybe it is a good idea to merge them and let me find time to continue improvements later (or somebody else).
Things changed / fixed:

  • catch write errors
  • fix crash on start in line 214 with .ts of undefined because of trailing slash in config and bogus ids for diskList
  • fix some errors / oversights with disk-ids in sync
  • fixed typo in some Regex which also caused disk-ids to go bogus
  • replaced deprecated use of new Buffer
  • rewrote createRecursiveDir to use node.js functionality (as per TODO comment)

Todo List:

  • catch all read errors
  • investigate possible issues and implement mirroring on multiple instances (at least on different hosts), probably including test cases.

bad type in replace logic -> caused some slashes to stay in id, ids of newly created files and files already on disk got different ids. Don't now if that can cause issues, but sure looks better this way.
if you have a tailing slash in diskRoot config variable this will cause a crash on adapter start with the following message
"uncaught exception: Cannot read property 'ts' of undefined"

This is because an off by one error here:
https://github.com/ioBroker/ioBroker.javascript/blob/master/lib/mirror.js#L505
-> i.e. the first letter of the id goes missing there, so this.diskList get's filled with wrong keys and causes this.diskList[id] to be undefined in sync later.
somehow file was used as index in some parts. Probably that got changed was overlooked? -> made those to be in line with rest of the code.
as requested by todo.
Also added a try / catch block there.
write is more ciritcal for right issues... we probably don't want a broken sync to crash whole adapter (and create a start-crash-loop).

Probably we should wrap all file operations in try / catch blocks.
@AlCalzone
Copy link
Collaborator

So, this fixes #551? If so, add "fixes #551" to the OP please :)

lib/mirror.js Outdated
@@ -480,8 +496,8 @@ class Mirror {
folderDirParts.pop();
Mirror.createRecursiveDir(folderDirParts.join('/'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If createRecursiveDir fails, should we even continue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should not. Not sure how to best change the situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, had an idea... hope you like it, see e7412ba.

there already was a function to handle the issue... let's just use it. ;-)
it was exlusively used before writeFile, so I added the recursive fs.mkdir there (using path.dirname instead of complicated manual path extraction) and let it throw errors -> if we can not create the dir, we do not try to write the file and print an error instead.
@Apollon77 Apollon77 merged commit dbece42 into ioBroker:master May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ständiger Neustart durch Mirroring-Funktion
3 participants