From: Chris Allegretta Date: Thu, 3 Jan 2013 03:07:27 +0000 (+0000) Subject: Fix trying to lock an un-writable directory. Just put a message X-Git-Tag: v2.3.2~20 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=21f73f902f55ceb49765c8415e405ad2c49bb0ea;p=nano.git Fix trying to lock an un-writable directory. Just put a message on the statusbar that we couldn't do it if the user modifies the file. Changes to do_lockfile and write_lockfile to check for EACCESS and change the return value of the functions (0 instead of -1) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4550 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/src/files.c b/src/files.c index 4f3d6b22..f15a05f8 100644 --- a/src/files.c +++ b/src/files.c @@ -116,7 +116,7 @@ void initialize_buffer_text(void) origfilename: name of the file the lock is for modified: whether to set the modified bit in the file - Returns: 1 on success, -1 on failure + Returns: 1 on success, 0 on failure (but continue loading), -1 on failure and abort */ int write_lockfile(const char *lockfilename, const char *origfilename, bool modified) { @@ -154,6 +154,13 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi fd = open(lockfilename, cflags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + + /* Maybe we just don't have write access, don't stop us from + opening the file at all, just don't set the lock_filename + and return success */ + if (fd < 0 && errno == EACCES) + return 1; + /* Now we've got a safe file stream. If the previous open() call failed, this will return NULL. */ filestream = fdopen(fd, "wb"); @@ -232,7 +239,9 @@ int delete_lockfile(const char *lockfilename) /* Deal with lockfiles. Return -1 on refusing to override - the lock file, and 1 on successfully created the lockfile. + the lock file, and 1 on successfully created the lockfile, 0 means + we were not successful on creating the lockfile but we should + continue to load the file and complain to the user. */ int do_lockfile(const char *filename) { diff --git a/src/winio.c b/src/winio.c index 29a74f2b..68692324 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2258,6 +2258,12 @@ void set_modified(void) if (!openfile->modified) { openfile->modified = TRUE; titlebar(NULL); +#ifndef NANO_TINY + if (ISSET(LOCKING) && openfile->lock_filename == NULL) + /* Translators: Try to keep this at most 80 characters. */ + statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); +#endif + } }