delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/02/07/02:00:43

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_05,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_YE,RCVD_VIA_APNIC,TW_CP,TW_YG
X-Spam-Check-By: sourceware.org
X-Authority-Analysis: v=2.0 cv=FNSZNpUs c=1 sm=1 a=3L1OLwb3Joj1WY/vcEmyWw==:17 a=XMX6KyidB00A:10 a=BHxaS1_h5ssA:10 a=Yq1-IuWEI7QA:10 a=-sTO_XvcksqKKhBpDoMA:9 a=QEXdDO2ut3YA:10 a=D0cnbGPprnFPlVd5SEgA:9 a=3L1OLwb3Joj1WY/vcEmyWw==:117
Message-ID: <511350F3.8040702@shaddybaddah.name>
Date: Thu, 07 Feb 2013 18:00:03 +1100
From: Shaddy Baddah <lithium-cygwin AT shaddybaddah DOT name>
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.5) Gecko/20120624 Icedove/10.0.5
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: stat() and tilde prefix (was bad bash tab completion)
References: <5024B4D4 DOT 6080409 AT shaddybaddah DOT name> <50F395D5 DOT 4050201 AT shaddybaddah DOT name> <20130114061747 DOT GB16739 AT ednor DOT casa DOT cgf DOT cx> <20130114100002 DOT GA22039 AT calimero DOT vinschen DOT de> <50F417F9 DOT 8040108 AT shaddybaddah DOT name> <20130114161307 DOT GB8617 AT calimero DOT vinschen DOT de> <50F54C93 DOT 9090702 AT shaddybaddah DOT name>
In-Reply-To: <50F54C93.9090702@shaddybaddah.name>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Note-from-DJ: This may be spam

--------------050302060202000001090700
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

On 15 Jan 2013 23:33, Shaddy Baddah wrote:
<snip>
>>> From what I make of it, there needs to be a patch that, although can
>>> work generically, adds checks only required for Cygwin. And therefore
>>> is specific to the Cygwin package.
>>>
>>> The check would be an extension of the file_exists() function, perhaps
>>> called tilde_file_exists(), which determines if the tilde prefix forms
>>> a directory component of the path (strchr('/')?). If it does not, the
>>> file_exists() check is sufficient. If it does, then the check of if
>>> that directory exists is logically and'ed to the result of
>>> file_exists().
>>>
>>> Does that sound about right?
>>
>> A check like this might be a good idea. Ultimately I would be glad to
>> be able to come up with more correct code in Cygwin while not getting
>> slower, of course. But that's wishful thinking for now.
>
> Bash, patched in the way I have described, seems to fix the tab
> completion issue.
>
> I will tidy up the work and publish the patch at some point soon. I may
> have taken a naive approach, so review comments are welcome.

Please find the patch discussed attached. It probably needs to be a bit
more generic, maybe with some precompiler directives to limit it to
cygwin? Although if it is just for cygwin, perhaps it can just go in the
cygports patch?

Do I need to put an "attn bash maintainer" on the subject line?

--------------050302060202000001090700
Content-Type: text/x-patch;
 name="cygwin-181692-bash-tilde-fix.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="cygwin-181692-bash-tilde-fix.diff"

diff --git a/bashline.c b/bashline.c
index 3cbb18f..31841fa 100644
--- a/bashline.c
+++ b/bashline.c
@@ -3478,8 +3478,9 @@ quote_word_break_chars (text)
       if (mbschr (rl_completer_word_break_characters, *s))
 	*r++ = '\\';
       /* XXX -- check for standalone tildes here and backslash-quote them */
-      if (s == text && *s == '~' && file_exists (text))
+      if (s == text && *s == '~' && tilde_file_exists (text)) {
         *r++ = '\\';
+      }
       *r++ = *s;
     }
   *r = '\0';
diff --git a/general.c b/general.c
index fdadf1d..b279cbe 100644
--- a/general.c
+++ b/general.c
@@ -544,6 +544,28 @@ file_exists (fn)
 }
 
 int
+tilde_file_exists (fn)
+     char *fn;
+{
+  struct stat sb;
+  char *slash, *dirpart;
+  int istildedir;
+
+  istildedir = 0;
+
+  slash = strchr (fn, '/');
+  if ((slash != 0) && (slash != fn))
+    {
+      dirpart = (char *)xmalloc ((slash - fn) + 1);
+      strncpy (dirpart, fn, (slash - fn) + 1);
+      istildedir = file_isdir (dirpart);
+      free (dirpart);
+    }
+
+  return (!((slash != 0) && (slash != fn) && ! istildedir) && (stat (fn, &sb) == 0));
+}
+
+int
 file_isdir (fn)
      char *fn;
 {
diff --git a/general.h b/general.h
index 2b31c58..f6b7ab4 100644
--- a/general.h
+++ b/general.h
@@ -302,6 +302,7 @@ extern int sh_openpipe __P((int *));
 extern int sh_closepipe __P((int *));
 
 extern int file_exists __P((char *));
+extern int tilde_file_exists __P((char *));
 extern int file_isdir __P((char  *));
 extern int file_iswdir __P((char  *));
 extern int dot_or_dotdot __P((const char *));


--------------050302060202000001090700
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--------------050302060202000001090700--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019