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
master
Benno Schulenberg 2016-01-31 13:06:06 +00:00
parent f96f4fe616
commit ba987350a9
3 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,7 @@
2016-01-31 Benno Schulenberg <bensberg@justemail.net>
* 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 <bensberg@justemail.net> 2016-01-29 Benno Schulenberg <bensberg@justemail.net>
* src/files.c (do_insertfile): Do display the buffer when configured * src/files.c (do_insertfile): Do display the buffer when configured
with only --disable-histories. This fixes Savannah bug #47011. with only --disable-histories. This fixes Savannah bug #47011.

View File

@ -38,20 +38,32 @@ bool has_valid_path(const char *filename)
{ {
char *parentdir; char *parentdir;
struct stat parentinfo; struct stat parentinfo;
bool validity = TRUE; bool validity = FALSE;
if (strrchr(filename, '/') == NULL) if (strrchr(filename, '/') == NULL)
parentdir = mallocstrcpy(NULL, "."); parentdir = mallocstrcpy(NULL, ".");
else else
parentdir = dirname(mallocstrcpy(NULL, filename)); parentdir = dirname(mallocstrcpy(NULL, filename));
if (stat(parentdir, &parentinfo) == -1 || !S_ISDIR(parentinfo.st_mode)) { if (stat(parentdir, &parentinfo) == -1) {
statusbar(_("Directory '%s' does not exist"), parentdir); if (errno == ENOENT)
validity = FALSE; statusbar(_("Directory '%s' does not exist"), parentdir);
beep(); 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); free(parentdir);
if (!validity)
beep();
return validity; return validity;
} }

View File

@ -280,8 +280,7 @@ void do_cut_till_eof(void);
#endif #endif
void do_uncut_text(void); void do_uncut_text(void);
/* All functions in files.c. */ /* Most functions in files.c. */
void verify_path(const char *filename);
void make_new_buffer(void); void make_new_buffer(void);
void initialize_buffer_text(void); void initialize_buffer_text(void);
bool open_buffer(const char *filename, bool undoable); bool open_buffer(const char *filename, bool undoable);