Stebalien / tempfile

Temporary file library for rust
http://stebalien.com/projects/tempfile-rs
Apache License 2.0
1.2k stars 120 forks source link

File is empty after being written to #269

Closed kirawi closed 10 months ago

kirawi commented 10 months ago

Here is a rough minimal example: https://github.com/kirawi/min-repro/blob/bb8195fd677465ecf5f1df1b047a310107e7c4f1/src/main.rs#L378-L397

On my PopOS machine, I am experiencing errors such as: Error: "assertionleft == rightfailed\n left: [72, 101, 108, 105, 120, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 26, 150, 101, 0, 0, 0, 0, 218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 26, 150, 101, 0, 0, 0, 0]\n right: []"

and I'm not sure what's going on. The vector indicates that stuff is being written correctly, but the file is empty even though the same content is written to it. I suspected that the write function is going through (since there are no panics from unwrapping results) but beyond that I'm lost.

kirawi commented 10 months ago

Alright, I figured it out. It turns out that after any read or write you have to seek to the beginning of the file. It was definitely not easy to find out for how simple the solution actually was, so I hope it can help anyone else dealing with the same problem.