From 940b5eaad116232c20de7405bbb7ba4a2eb8e779 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 5 Apr 2022 12:23:32 +0200 Subject: [PATCH] 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. --- src/files.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/files.c b/src/files.c index 6641de01..51bc1dce 100644 --- a/src/files.c +++ b/src/files.c @@ -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. */