Saving a file with VSC results in an error, opening and saving the file with vi on linux leads to no error

When editing a file using Visual Studio Code on Windows 10 I get the following error:

2018-04-04 21:12:21.024 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'lights.rules'

2018-04-04 21:12:21.040 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'lights.rules' is either empty or cannot be parsed correctly!

2018-04-04 21:12:21.251 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'lights.rules'

However opening the same file on the openhabianpi server with vi and saving it results in

2018-04-04 23:12:24.381 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'lights.rules'

And no errors in the log.

Could this have something to do with timing due to samba/cifs?

Never mind, I fixed it.

I modified the ownership of the config folder to be openhiabian:openhabian on linux in stead of openhab:openhab.

Are you sure that fixed it and you are still getting the Loading model log statement?

That error is a minor annoyance but nothing to worry about. The problem is OH uses file events to know when to load the files. When using certain editors or editing files over SAMBA what happens is two file events are generated, one when the editor first starts to save the file and then another when it is done. OH tries to read the file on the first event but because the file is incomplete (likely blank at this point) it generates the error. Then it tries to read the file again on the second event and because the file has been fully written it is able to read it normally.

This is why you do not see the error when you edit via vi.

Changing the ownership of the files should not change this behavior which makes me think that OH now no longer has permission to read the file or something like that is happening.

You might be correct in your assumption on the way samba messes this up for OH. I will have a look at samba and find out if it can change the modification until after the complete write of a file.

I have changed the permissions correctly as OH can still read the files.

Thanks Rich for the support.

I don’t think it can. Lots of people have looked into it. I suspect what happens is when writing to a file it first creates a blank file (file event 1) then it opens and writes the contents to that file (file event 2). If I’m correct (I’ve seen some anecdotal evidence that I am correct) there is nothing you can do. It is fundamental to how samba and/or Windows file operations work.

It is mysterious as to why changing the ownership of the files would avoid the problem though.

I followed a post somewhere where it said files and folder should be from openhab:openhab, so I changed owner and group accordingly. I later on changed it back and the error disappeared, so I thought it fixed it.

Later I thought it was an empty newline at the end of the file after the last END, removing that line also seemed to fix it.

But later the error occurred again.

So I thought I fixed it, and you were correct that I didn’t.

Anyway I’ll keep on forging ahead.

1 Like