In-place formatting empties out target files on any error

Easiest way to reproduce is to try to use a non-existing config file path:

muon fmt -i -c /file/that/does/not/exist meson.build.

However, this also happens if there is an error in the configuration file, or there was an error while parsing meson.build, etc.

This happens because target file path is opened for writing before calling fmt(). I think the best way to fix this would be to instead write to a file called $target_file.$pid.tmp or something along the lines, and then rename it $target_value essentially overwriting the fie.

Assigned to
2 months ago
2 months ago
No labels applied.

~lattis REPORTED FIXED 2 months ago

This should be fixed now. Since we already have the original file contents in memory, I implemented this by just rewriting those original contents to the file if an error occurs.

I also found out that fmt -i -q meson.build will truncate the file, and fixed that by erroring if both -i and -q are passed.

Register here or Log in to comment, or comment via email.