diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-30 20:39:54 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-08-02 19:26:24 +0200 |
commit | e32cf3d478e746e1a83a1289e47399087fe1fda3 (patch) | |
tree | 2906b3c3373a69f6dadd41e23bd04ec989853006 /.editorconfig | |
parent | dc5c35758dca410350ff36f9bf5c9090236e6043 (diff) | |
download | aerc-e32cf3d478e746e1a83a1289e47399087fe1fda3.tar.gz |
composer: reopen the email file when editor is closed
Some text editors save changes in a temp file before moving it over to
the destination instead of rewriting the original file in place. This
protects against all sorts of corruption, like writing partial files in
disk-full scenarios for example. When this is the case, aerc's open file
descriptor points to a different file, one that was never written to by
the editor.
For text editors that *do* overwrite the file (i.e. the same filesystem
inode id), depending on timing, kernel version, operating system,
filesystem options, caching, etc. Reading from aerc's file descriptor
after the text editor has modified the same file on disk may not return
the updated data. This behaviour can be easily observed with the
following C program:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void) {
int fd;
ssize_t n;
char buf[BUFSIZ];
unlink("test.txt");
fd = open("test.txt", O_CREAT|O_RDWR, 0644);
write(fd, "Bonjour\n", strlen("Bonjour\n"));
fsync(fd);
lseek(fd, 0, SEEK_SET);
n = read(fd, buf, sizeof(buf));
buf[n] = '\0';
printf("before: %s\n", buf);
system("vim test.txt");
lseek(fd, 0, SEEK_SET);
n = read(fd, buf, sizeof(buf));
buf[n] = '\0';
printf("after: %s\n", buf);
return 0;
}
Most of the time, before and after texts will be identical even if you
modified the test.txt file contents in the editor.
The only reliable way to ensure to read the latest contents from the
disk is to close and reopen the file after the text editor has exited.
Do exactly that in termClosed before anything else.
Fixes: 801caf812377 ("compose: factorize body read in a method")
Fixes: https://todo.sr.ht/~rjarry/aerc/184
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Ronald Evers <ronald@ch10.nl>
Diffstat (limited to '.editorconfig')
0 files changed, 0 insertions, 0 deletions