From ba987350a9dd026d187be31537d0c47223c3289d Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 31 Jan 2016 13:06:06 +0000 Subject: [PATCH] Being more specific in how a given path is invalid. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5602 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/files.c | 22 +++++++++++++++++----- src/proto.h | 3 +-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3db565b..6872cdc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-01-31 Benno Schulenberg + * src/files.c (has_valid_path): Be more specific in how a given path + is invalid. The change was improved by Rishabh Dave. + 2016-01-29 Benno Schulenberg * src/files.c (do_insertfile): Do display the buffer when configured with only --disable-histories. This fixes Savannah bug #47011. diff --git a/src/files.c b/src/files.c index 604c7738..a7aa1c59 100644 --- a/src/files.c +++ b/src/files.c @@ -38,20 +38,32 @@ bool has_valid_path(const char *filename) { char *parentdir; struct stat parentinfo; - bool validity = TRUE; + bool validity = FALSE; if (strrchr(filename, '/') == NULL) parentdir = mallocstrcpy(NULL, "."); else parentdir = dirname(mallocstrcpy(NULL, filename)); - if (stat(parentdir, &parentinfo) == -1 || !S_ISDIR(parentinfo.st_mode)) { - statusbar(_("Directory '%s' does not exist"), parentdir); - validity = FALSE; - beep(); + if (stat(parentdir, &parentinfo) == -1) { + if (errno == ENOENT) + statusbar(_("Directory '%s' does not exist"), parentdir); + else + statusbar(_("Path '%s': %s"), parentdir, strerror(errno)); + } else if (!S_ISDIR(parentinfo.st_mode)) { + statusbar(_("Path '%s' is not a directory"), parentdir); + } else { + if (access(parentdir, X_OK) == -1) + statusbar(_("Path '%s' is not accessible"), parentdir); + else + validity = TRUE; } free(parentdir); + + if (!validity) + beep(); + return validity; } diff --git a/src/proto.h b/src/proto.h index 2e342bd3..f8ca6a8a 100644 --- a/src/proto.h +++ b/src/proto.h @@ -280,8 +280,7 @@ void do_cut_till_eof(void); #endif void do_uncut_text(void); -/* All functions in files.c. */ -void verify_path(const char *filename); +/* Most functions in files.c. */ void make_new_buffer(void); void initialize_buffer_text(void); bool open_buffer(const char *filename, bool undoable); -- 2.39.5