From 6d5b2fd9366fd71515ef8683d4afc128a92d52f4 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 3 Jul 2014 03:54:22 +0000 Subject: [PATCH] 2014-07-02 Chris Allegretta * src/files.c (do_lockfile): Check whether the directory of the file we're trying to lock exists, and make the resulting error message more intuitive. Fixes Savannah bug 42639 by bens. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5056 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/files.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f16633ef..475c8ab7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-07-02 Chris Allegretta + * src/files.c (do_lockfile): Check whether the directory + of the file we're trying to lock exists, and make the + resulting error message more intuitive. Fixes + Savannah bug 42639 by bens. + 2014-07-02 Mark Majeres * src/text.c (undo_cut, redo_cut, update_undo): Handle the cases of cutting-from-cursor-to-end-of-line correctly. diff --git a/src/files.c b/src/files.c index 18baacc3..97a2e88e 100644 --- a/src/files.c +++ b/src/files.c @@ -141,7 +141,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi mypid = getpid(); if (gethostname(myhostname, 31) < 0) { - statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno)); + statusbar(_("Couldn't determine hosttname for lock file: %s"), strerror(errno)); return -1; } @@ -247,6 +247,7 @@ int do_lockfile(const char *filename) size_t lockfilesize = strlen(filename) + strlen(locking_prefix) + strlen(locking_suffix) + 3; char *lockfilename = charalloc(lockfilesize); + char *lockfilecpy = NULL; char lockprog[12], lockuser[16]; struct stat fileinfo; int lockfd, lockpid; @@ -294,8 +295,17 @@ int do_lockfile(const char *filename) blank_statusbar(); return -1; } + } else { + lockfilecpy = mallocstrcpy(NULL, lockfilename); + lockfilecpy = dirname(lockfilecpy); + if (stat(lockfilename, &fileinfo) == -1) { + statusbar(_("Error writing lock file: Directory \'%s\' doesn't exist"), + lockfilecpy); + return -1; + } } + return write_lockfile(lockfilename, filename, FALSE); } #endif /* !NANO_TINY */ -- 2.39.5