Index: src/global.c =================================================================== --- src/global.c (revision 5569) +++ src/global.c (working copy) @@ -40,6 +40,8 @@ /* Whether the current keystroke is an extended keypad value. */ bool focusing = FALSE; /* Whether an update of the edit window should center the cursor. */ +bool faulty_path = FALSE; + /* Whether path of file is faulty or not. */ #ifndef NANO_TINY int controlleft = CONTROL_LEFT; Index: src/files.c =================================================================== --- src/files.c (revision 5571) +++ src/files.c (working copy) @@ -33,6 +33,24 @@ #include #include +/* Determine whether the components in a path are valid directories. If + * some component is faulty, display faulty path and turn faulty_path TRUE. */ + void fault_in_path(const char *filename) +{ + char *parentdir = (char *) mallocstrcpy(NULL, filename); + struct stat parentinfo; + + parentdir = dirname(parentdir); + if (stat(parentdir, &parentinfo) != -1 && S_ISDIR(parentinfo.st_mode)) { + faulty_path = FALSE; + } else { + statusbar(_("Directory '%s' does not exist"), parentdir); + beep(); + faulty_path = TRUE; + } + free(parentdir); +} + /* Add an entry to the openfile openfilestruct. This should only be * called from open_buffer(). */ void make_new_buffer(void) @@ -112,7 +130,7 @@ titlebar(NULL); #ifndef NANO_TINY - if (!ISSET(LOCKING) || openfile->filename[0] == '\0') + if (!ISSET(LOCKING) || faulty_path || openfile->filename[0] == '\0') return; if (openfile->lock_filename == NULL) { @@ -282,7 +300,6 @@ size_t locknamesize = strlen(filename) + strlen(locking_prefix) + strlen(locking_suffix) + 3; char *lockfilename = charalloc(locknamesize); - char *lockfiledir = NULL; static char lockprog[11], lockuser[17]; struct stat fileinfo; int lockfd, lockpid; @@ -331,18 +348,7 @@ blank_statusbar(); return -1; } - } else { - lockfiledir = mallocstrcpy(NULL, lockfilename); - lockfiledir = dirname(lockfiledir); - if (stat(lockfiledir, &fileinfo) == -1) { - statusbar(_("Error writing lock file: Directory \'%s\' doesn't exist"), - lockfiledir); - free(lockfiledir); - return 0; } - free(lockfiledir); - } - return write_lockfile(lockfilename, filename, FALSE); } #endif /* !NANO_TINY */ @@ -393,6 +399,9 @@ if (new_buffer) { make_new_buffer(); + fault_in_path(filename); + + if (!faulty_path) { #ifndef NANO_TINY if (ISSET(LOCKING) && filename[0] != '\0') { int lockstatus = do_lockfile(filename); @@ -409,6 +418,7 @@ } #endif } + } /* If the filename isn't blank, and we are not in NOREAD_MODE, * open the file. Otherwise, treat it as a new file. */ @@ -963,7 +973,7 @@ } if (newfie) { - if (!quiet) + if (!quiet && !faulty_path) statusbar(_("New File")); return -2; } Index: src/proto.h =================================================================== --- src/proto.h (revision 5567) +++ src/proto.h (working copy) @@ -34,6 +34,7 @@ extern bool meta_key; extern bool func_key; extern bool focusing; +extern bool faulty_path; #ifndef NANO_TINY extern int controlleft; @@ -281,6 +282,7 @@ void do_uncut_text(void); /* All functions in files.c. */ +void fault_in_path(const char *filename); void make_new_buffer(void); void initialize_buffer_text(void); bool open_buffer(const char *filename, bool undoable);