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-d3aeb78583b8master
parent
bf88d27adc
commit
21f73f902f
13
src/files.c
13
src/files.c
|
@ -116,7 +116,7 @@ void initialize_buffer_text(void)
|
||||||
origfilename: name of the file the lock is for
|
origfilename: name of the file the lock is for
|
||||||
modified: whether to set the modified bit in the file
|
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)
|
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,
|
fd = open(lockfilename, cflags,
|
||||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
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()
|
/* Now we've got a safe file stream. If the previous open()
|
||||||
call failed, this will return NULL. */
|
call failed, this will return NULL. */
|
||||||
filestream = fdopen(fd, "wb");
|
filestream = fdopen(fd, "wb");
|
||||||
|
@ -232,7 +239,9 @@ int delete_lockfile(const char *lockfilename)
|
||||||
|
|
||||||
|
|
||||||
/* Deal with lockfiles. Return -1 on refusing to override
|
/* 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)
|
int do_lockfile(const char *filename)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2258,6 +2258,12 @@ void set_modified(void)
|
||||||
if (!openfile->modified) {
|
if (!openfile->modified) {
|
||||||
openfile->modified = TRUE;
|
openfile->modified = TRUE;
|
||||||
titlebar(NULL);
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue