rayrobdod / png-inflate

A clean filter for git that decompresses png images
Apache License 2.0
2 stars 0 forks source link

Truncate output file #4

Closed rayrobdod closed 3 years ago

rayrobdod commented 3 years ago

If the program output is to a file, a file already exists at that location, and the program output is smaller than the existing file contents, then the output file is not shrunk, and the file contains garbage data at the end.

Options:

  1. Open output file as truncate. Simple, but if the input file and output file are the same file, have to read the file before opening the output file
  2. File::set_len. Would have to be done at the end of the program, and need to be a special case when closing a file (whereas all current special casing is when opening the file)(using a deconstructor, maybe?)
  3. Two-stage file saving. Even more steps than set_len - especially if attempting to preserve file permissions, does rust have an atomic "create temporary file" method - but has the best resistance to data loss
rayrobdod commented 3 years ago

Fix merged into main as of 260699452c0e6bb5e995427b55e21ba8c666c470