save: Use dd with the notrunc & fsync and postpone truncation by JoeKar · Pull Request #3814 · micro-editor/micro (original) (raw)

@JoeKar mentioned this pull request

Jul 22, 2025

@JoeKar

@JoeKar JoeKar changed the titlesave: Use dd with the notrunc and fsync option save: Use dd with the notrunc option

Jul 24, 2025

dmaluka

dmaluka

@JoeKar JoeKar changed the titlesave: Use dd with the notrunc option save: Use dd with the notrunc & fsync option and truncate as command

Jul 31, 2025

niten94

@JoeKar JoeKar changed the titlesave: Use dd with the notrunc & fsync option and truncate as command save: Use dd with the notrunc & fsync and postpone truncation

Aug 5, 2025

dmaluka

niten94

@JoeKar

Using notrunc will stop the overall truncation of the target file done by sudo. We need to do this because dd, like other coreutils, already truncates the file on open(). In case we can't store the backup file afterwards we would end up in a truncated file for which the user has no write permission by default. Instead we use a second call of dd to perform the necessary truncation on the command line. With the fsync option we force the dd process to synchronize the written file to the underlying device.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})