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

possible problem #2

Open
dominictarr opened this issue Dec 14, 2013 · 3 comments
Open

possible problem #2

dominictarr opened this issue Dec 14, 2013 · 3 comments

Comments

@dominictarr
Copy link

I've recently been bitten by downloading files and writing them directly
to where I want them to live. If the program crashes before they are fully downloaded, then when it's started again, they program doesn't know that file is corrupt.

the solution is to stream to a temporary location, and then mv the files (fs.rename) it into position. the rename is atomic, so this means it fails or succeeds cleanly.

I'm not sure if problem will affect for code, because you are buffering.
but maybe it will, if the file size is greater than a block?

https://github.com/creationix/git-fs-db/blob/master/fs-db.js#L42-L47

@creationix
Copy link
Owner

What's wrong with partial writes? If the hash doesn't match the content, then we can tell it's corrupt after the fact. Or am in misunderstanding the problem?

@dominictarr
Copy link
Author

sure, you could deal with it at one end or the other,
I only post this because this has bitten me recently,
and so I'm paranoid about it.

To me, It feels more complicated to handle that when you are reading, though.

@creationix
Copy link
Owner

Well, even with atomic writes using renames and temp files, you still have the issues of dangling references between files and other inconsistencies. We could add atomic writes to this db implementation (no reason not to), but it won't remove the need to check everything on read.

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

No branches or pull requests

2 participants