delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/08/17:36:53

X-Spam-Check-By: sourceware.org
Message-ID: <440F5C73.7050300@ukf.net>
Date: Wed, 08 Mar 2006 22:36:35 +0000
From: Max Bowsher <maxb1 AT ukf DOT net>
Reply-To: cygwin AT cygwin DOT com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050923 Thunderbird/1.0.7
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: [BUG] rename("symlink", "regular_file") has weird results
OpenPGP: id=C0F2C580
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Suppose "foo.tmp" is a symlink, and "foo" is a regular file.

Calling rename("foo.tmp", "foo") results in the very bizarre situation
where, as far as Cygwin is concerned, there are TWO files called "foo"
within the same directory.

Below is a small C program to reproduce this state of affairs.

Max.

=====================================================================

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

#define M1BAD(x) if ((x) == -1) { handle_error(#x); }
#define ZOK(x) if ((x) != 0) { handle_error(#x); }
static void handle_error(char *op)
{
    fprintf(stderr, "E: %s: %s\n", op, strerror(errno));
    exit(1);
}

int main(void)
{
  int fd;

  M1BAD(fd = open("foo", O_CREAT, 0644));
  ZOK(close(fd));

  ZOK(symlink("nonexistent", "foo.tmp"));

  ZOK(rename("foo.tmp", "foo"));

  return 0;
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFED1xzfFNSmcDyxYARAt9aAKCYNk2A4N0PNNv/Xi42WEE0h5ZJGgCfYfa/
F/Rm9fGDC1vQJKooGL/cYcs=
=+BiT
-----END PGP SIGNATURE-----

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

- Raw text -


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