fix(eas): allow path/to/output & add clean-up - #115
Conversation
| match std::fs::write(&opt.out.unwrap(), &out_file_content) { | ||
| Ok(_) => (), | ||
| Err(e) => panic!("couldn't restore existing file.\n{}", e), | ||
| }; |
There was a problem hiding this comment.
The idea is to only modify the output if the compilation succeeds, but leave the file untouched otherwise?
This particular approach will fail to restore the file if, say, there's a panic.
What would you think of using something like tempfile to make a temporary file in the same directory as the intended output, then moving the file into the intended output?
So to write to a file a/b/test.foo, you'd do:
- Create
a/b/test.foo.tmpusingtempfile. ingest_file(...).std::fs::renamefroma/b/test.foo.tmptoa/b/test.foo.
There was a problem hiding this comment.
Hi, @SamWilsn. Yes, that was the idea - don’t create a file or overwrite the existing one with the same name if eas fails.
tempfile sounds like a good option.
Sorry I won’t be able to make the changes - I won’t have a computer with me for a while.
I’d recommend the following approach:
- Create a temporary file in the current directory
- Ingest
- If successful, create directories on the out path that don’t exist, and move + rename the file
This way, neither new directories nor an output file will be created if the compilation fails, which is cleaner.
Let me know what you think.
Gm! ETK is an amazing toolkit and I wanted to contribute.
This is my fist time working with Rust - feel free to make any changes and merge/close the PR, because I'll be AFK.
Motivation
easerrors if a directory on the path to the output file doesn't exist.easfails. In case of an existing file, that one will be overwritten.Solution
easfails.Thanks!