nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] Checking permissions before opening file


From: Benno Schulenberg
Subject: Re: [Nano-devel] Checking permissions before opening file
Date: Wed, 27 Jan 2016 17:52:24 +0100

On Tue, Jan 26, 2016, at 21:48, Mike Frysinger wrote:
> On 26 Jan 2016 21:03, Benno Schulenberg wrote:
> > +   if (errno == ENOENT)
> > +       statusbar(_("Path '%s' does not exist"), parentdir);
> > +   else
> > +       statusbar(_("Path '%s': %s"), parentdir, strerror(errno));
> 
> why is this needed ?  the strerror() for ENOENT is already:
>       No such file or directory

I don't like the words "No such *file*..."  It's not supposed to be
a file, it /must/ be a directory.  That's why I split out that one
case, to give a clearer error message.


> > +    } else if (!S_ISDIR(parentinfo.st_mode)) {
> > +   statusbar(_("Path '%s' is not a directory"), parentdir);
> > +   beep();
> > +    } else {
> > +   if (access(parentdir, X_OK) != -1)
> > +       validity = TRUE;
> > +   else {
> > +       statusbar(_("Path '%s' is not accessible"), parentdir);
> > +       beep();
> > +   }
> 
> i don't think this check is useful.  it should just attempt the open
> (or whatever) and diagnose problems when that fails.

Well, currently, when a thing does not exist, nano just assumes it
is a new file, and will say so.  But if you have 'set locking' in your
nanorc, then it will try to write a lock file, and will fail, and will
complain about that:

  [ Error writing lock file /root/.yuuhuu.swp: Permission denied ]

The new permission check is included to avoid that ugly error
message and give a more meaningful one instead.

> there's no way
> to guarantee the path will stay valid after this func returns.

True.  And also at write time the situation and permissions might
have changed.  But that doesn't matter.  The most likely cause
for this message to appear is that the user has made a typo or
a thinko.  Nano is trying to be friendly and helpful, saying the
equivalent of: "this is probably not what you want to do".

Benno

-- 
http://www.fastmail.com - IMAP accessible web-mail




reply via email to

[Prev in Thread] Current Thread [Next in Thread]