Skip to content

code-server deletes olds version when updating #1483

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

Closed
niv-d opened this issue Apr 2, 2020 · 12 comments · Fixed by #1486
Closed

code-server deletes olds version when updating #1483

niv-d opened this issue Apr 2, 2020 · 12 comments · Fixed by #1486

Comments

@niv-d
Copy link

niv-d commented Apr 2, 2020

Coder server just updated, and deleted my projects folder.

Is there anyway to retrieve it? I don't have a backup.
Infact, it delted all configs. It wiped the folder that coder was in an replaced it all.

@niv-d niv-d changed the title Code Server Updated Code Server Updated - All files gone. Apr 2, 2020
@kylecarbs
Copy link
Member

Huge problem. Could you elaborate on your directory structure?

@nhooyr
Copy link
Contributor

nhooyr commented Apr 2, 2020

@dmratcliffe Were you placing your files in the directory code-server was unpacked into?

Regardless, we'll change code-server asap to move the files instead of deleting.

@nhooyr nhooyr changed the title Code Server Updated - All files gone. code-server deletes olds version when updating Apr 2, 2020
@niv-d
Copy link
Author

niv-d commented Apr 2, 2020

To give more information, my code-server was setup like so:

/home/coder/code-server - the binary of code server
/home/coder/extenstions - the location of extenstions, setup with the command line switch on the coder binary, I had a similar folder for the user data too, forgot the names.
/home/coder/project - the folder coder would load by default, had numerous projects and folders.

It had been setup like this forever, and updates previously had never destroyed my files. It seems insane that an update could even do this.

I don't mean to nitpick, but why was it set to delete files that it didn't create? Did it just run rm * on its folder? Why was there no warning? Why did it happen now and not before?

@nhooyr
Copy link
Contributor

nhooyr commented Apr 2, 2020

/home/coder/code-server - the binary of code server

Does this mean you were on V2?

@nhooyr
Copy link
Contributor

nhooyr commented Apr 2, 2020

It seems insane that an update could even do this.

Yes it's insane and unexpected so we're gonna try to fix whatever it is asap.

@niv-d
Copy link
Author

niv-d commented Apr 2, 2020

No, I had recently updated it to v3, with all the node folders and such.
I believe I still used code-server to run it, and in turn I had gotten the update notification for 3.0.2, when it restarted is when this happened.

Sorry for the delay, trying to recover the files.

@niv-d
Copy link
Author

niv-d commented Apr 2, 2020

Hey, I did some looking and I believe the reason it was overwritten is because the move command will overwrite the entire directory if a directory is given as the destination.

I think that's why, which means the current patch will defeat this by moving the files out before updating?*

Not sure, baseing this stuff of the documentation of fs.move found here:
https://github.com/jprichardson/node-fs-extra/blob/master/docs/move.md
image

and the implentation that made this happen (I think this is the spot maybe I'm wrong?):
https://github.com/cdr/code-server/blob/d192726e805a5ea608953354ca77ee8cda1647f7/src/node/app/update.ts
image

I think the proper fix would be to fs.move each file indivually?

*small edit cause I misspoke

@code-asher
Copy link
Member

You're right, that's exactly what caused this issue. When the new code-server directory was moved on top of the old one it overwrote the old one entirely.

The commit I just made renames the current code-server directory with a timestamp suffix so it won't get overridden. I also removed the { overwrite: true } so it won't be able to overwrite even if the directory wasn't moved.

We could move each file individually but then we might encounter unexpected side effects, such as what might happen if code-server crashed or was killed partway through the update. There's also no guarantee that we wouldn't accidentally overwrite a file the user modified or created if it happens to share the same name. I think renaming the directory is the safest (and fastest) option when considering all the potential edge cases.

@nhooyr
Copy link
Contributor

nhooyr commented Apr 3, 2020

@dmratcliffe Really sorry about this whole situation, hope you can recover your files!

@niv-d
Copy link
Author

niv-d commented Apr 3, 2020

@nhooyr Thanks, filetree was gone, photorec is promising but theres 40gbs of random scambled files :/

@code-asher
Copy link
Member

@dmratcliffe Just as a heads up, we're going to release 3.1.0 today. It has the update fixes but 3.0.2 still has the old code so an automatic update from 3.0.2 to 3.1.0 will delete the old version again. I hope you've had some luck in the recovery process, sorry again!

@niv-d
Copy link
Author

niv-d commented Apr 9, 2020

@code-asher For sure. Thanks for the headsup.

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 a pull request may close this issue.

4 participants