ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-apps/2002/01/14/16:17:48

Mailing-List: contact cygwin-apps-help AT cygwin DOT com; run by ezmlm
Sender: cygwin-apps-owner AT cygwin DOT com
List-Subscribe: <mailto:cygwin-apps-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-apps/>
List-Post: <mailto:cygwin-apps AT cygwin DOT com>
List-Help: <mailto:cygwin-apps-help AT cygwin DOT com>, <http://sources.redhat.com/lists.html#faqs>
Delivered-To: mailing list cygwin-apps AT cygwin DOT com
Date: Mon, 14 Jan 2002 22:16:50 +0100
From: Corinna Vinschen <vinschen AT redhat DOT com>
To: cygapp <cygwin-apps AT cygwin DOT com>
Subject: Preliminary patch for symlink problem in setup.exe
Message-ID: <20020114221650.D2015@cygbert.vinschen.de>
Reply-To: cygwin-apps AT cygwin DOT com
Mail-Followup-To: cygapp <cygwin-apps AT cygwin DOT com>
Mime-Version: 1.0
User-Agent: Mutt/

I've found a problem in setup.exe which potentially results in
two symlinks with the same name.

As you know, the default setting for symlinks in Cygwin is using
Windows shortcuts while setup.exe always creates symlinks as
the old-style system files.

Now imagine the following simple situation

- Delete /usr/bin/slogin by mistake.

- Recreate /usr/sbin/slogin with ln(1) creates a Windows shortcut

- A new OpenSSH package is downloaded using setup.exe.

Now look into the /usr/bin directory.  You will find two files,
`slogin' and `slogin.lnk'.

The following patch is a quick hack which I'd like to get reviewed
by the active setup contributors (not me).

The additional advantage of that patch is that it alleviates the
problem that setup complains when a file couldn't be installed
because the file already exists and couldn't be unlinked before.
That happens mostly when the R/O file attribute is set since
DeleteFile() fails then.

Oh, and I'm using the new INVALID_FILE_ATTRIBUTES define which
I found in the latest MSDN (surprise, surprise) and which
substitutes all prior ((DWORD) -1) or 0xffffffff constants
to mark the return code of GetFileAttributes() for ... yeah, you
guessed it, invalid file attributes.


2002-01-14  Corinna Vinschen  <corinna AT vinschen DOT de>

	* package_meta.cc (packagemeta::uninstall): Uninstall a file
	even with trailing ".lnk".  Unset R/O file attribute before
	trying to delete file.

Index: package_meta.cc
RCS file: /cvs/src/src/winsup/cinstall/package_meta.cc,v
retrieving revision 2.11
diff -u -p -r2.11 package_meta.cc
--- package_meta.cc	2002/01/06 11:31:47	2.11
+++ package_meta.cc	2002/01/14 21:08:44
@@ -120,11 +120,22 @@ packagemeta::uninstall ()
 	  dirs.add_subdirs (line);
+	  char buf[512];
 	  char *d = cygpath ("/", line, NULL);
 	  DWORD dw = GetFileAttributes (d);
-	  if (dw != 0xffffffff && !(dw & FILE_ATTRIBUTE_DIRECTORY))
+	      /* Check for Windows shortcut. */
+	      strcpy (buf, d);
+	      strcat (buf, ".lnk");
+	      d = buf;
+	      dw = GetFileAttributes (d);
+	    }
+	    {
 	      log (LOG_BABBLE, "unlink %s", d);
+	      SetFileAttributes (d, dw & ~FILE_ATTRIBUTE_READONLY);
 	      DeleteFile (d);
 	  line = installed->getnextfile ();

Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin AT cygwin DOT com
Red Hat, Inc.

- Raw text -

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