File written to by the program not saving occasionally
I have a program in Go that allows me to make and edit articles.
Sometimes, though the program won't save an edit of the article. The articles are stored via a
I have noticed that this usually happens if I close out of the window after it says it has successfully been edited, OR I close out of the computer. It always saves if I open the repl and check if it has been saved (as far as I know).
@tussiez told me that it was simply replit not saving sometimes, but I start to doubt that. It shows the edited article, but if I come back the next day the new edit is gone! It must be deleting the contents of the edit, but why? Also, how would I fix this?
Help would be appreciated.
- A confused bacon
Replit doesn't allow repls to edit files. It creates a new instance of the repl and anything changed will just revert to how it was programmed. You should try using the Replit database, which doesn't reset unless you tell it to.
@xxpertHacker So, how would I make sure it saves?
If it saves because the program is still executing, then why does it have this problem at all? Wouldn't it always save because it always writes to the file while the program is executing?
Is there a surefire workaround for this, then?
@Baconman321 try running the program in the same tab as it's code on replit. Does it work? If it does, I think it works because it's running as the owner, and gives itself permission write. Does it work on the site in a new tab? If it does, I'm very confused. If it doesn't, I think the new tab is a new instance of the program, and the instance of it is greater on replit, so it overwrites the data (the one running in replit). This is just a theory, so of course I don't know if it's correct.
Is this a text file on replit? Becuase occasionally replit will not save what your code has written to a text file if you are say; opening it in another tab or something. This is because replit does not save changes unless they are made by you, if that makes any sense.
Well sometimes if you haven't closed the file, for example when you do something like
files = open('file',w) and forget to do
files.close() it doesn't save. Also could you put your code, and when it say it's been edited has the file actually been edited.
@robowolf Yeah, but AFAIK
ioutil.WriteFile doesn't have a close method :/
I think the method I use already closes it for me when it's done.
My friend did recommend to me that I should check if the contents of the file are edited. I just want to know what is going on...
It saves but the next day it is gone!
@Andy_4sberg Yeah, Go supports DB functions, but I don't want to use it rn.
replit's database isn't as good as file storage IMO, except for the fact that it actually saves the content.
If replit DB got much better (increased key name range and more storage size), then yes I think I'd use it.