files: show a warning when the working directory is gone (when used)

Instead of silently opening an empty buffer when the user tries to
open a file in the current but disappeared directory, give a clear
warning about the absence of this directory.

This improves the fix for https://savannah.gnu.org/bugs/?62244.
This commit is contained in:
Benno Schulenberg 2022-04-05 12:23:32 +02:00
parent fdd946c02c
commit 940b5eaad1
1 changed files with 8 additions and 0 deletions

View File

@ -351,6 +351,14 @@ bool has_valid_path(const char *filename)
struct stat parentinfo;
bool validity = FALSE;
if (strcmp(parentdir, ".") == 0) {
char *currentdir = realpath(".", NULL);
if (currentdir == NULL)
statusline(ALERT, _("The working directory has disappeared"));
free(currentdir);
} else
if (stat(parentdir, &parentinfo) == -1) {
if (errno == ENOENT)
/* TRANSLATORS: Keep the next ten messages at most 76 characters. */