commit b60fec5db33c0532e0e7ac796a31275beb5e85b7
parent 7ffbf016077a81ac9b72fc1438fbf2e3eb557ee5
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 22 Aug 2020 10:20:24 +0200
history: do not interpret a failing stat() as an error
The most likely reason for stat() returning -1 is that the file
does not exist. And an absent positionlog file is not an error.
(In some cases it is, like immediately after writing the file,
but even then we don't want to complain, because it may have
been some other process that deleted the file straightaway.)
This fixes https://savannah.gnu.org/bugs/?58993.
Bug existed since version 5.0, commit fcb9e58b.
Diffstat:
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/history.c b/src/history.c
@@ -447,9 +447,7 @@ void load_poshistory(void)
free(line);
- if (stat(poshistname, &fileinfo) == -1)
- jot_error(N_("Error reading %s: %s\n"), poshistname, strerror(errno));
- else
+ if (stat(poshistname, &fileinfo) == 0)
latest_timestamp = fileinfo.st_mtime;
}
@@ -493,9 +491,7 @@ void save_poshistory(void)
if (fclose(histfile) == EOF)
jot_error(N_("Error writing %s: %s\n"), poshistname, strerror(errno));
- if (stat(poshistname, &fileinfo) == -1)
- jot_error(N_("Error writing %s: %s\n"), poshistname, strerror(errno));
- else
+ if (stat(poshistname, &fileinfo) == 0)
latest_timestamp = fileinfo.st_mtime;
}
@@ -504,9 +500,7 @@ void reload_positions_if_needed(void)
{
struct stat fileinfo;
- if (stat(poshistname, &fileinfo) == -1)
- jot_error(N_("Error reading %s: %s\n"), poshistname, strerror(errno));
- else if (fileinfo.st_mtime != latest_timestamp) {
+ if (stat(poshistname, &fileinfo) == 0 && fileinfo.st_mtime != latest_timestamp) {
poshiststruct *item, *nextone;
for (item = position_history; item != NULL; item = nextone) {