[PATCH] check_file_directory_conflict path fix
authorDavid Meybohm <dmeybohmlkml@bellsouth.net>
Fri, 27 May 2005 02:59:10 +0000 (22:59 -0400)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 27 May 2005 17:34:24 +0000 (10:34 -0700)
check_file_directory_conflict can give the wrong answers. This is
because the wrong length is passed to cache_name_pos. The length
passed should be the length of the whole path from the root, not
the length of each path subcomponent.

$ git-init-db
defaulting to local storage area
$ mkdir path && touch path/file
$ git-update-cache --add path/file
$ rm path/file
$ mkdir path/file && touch path/file/f
$ git-update-cache --add path/file/f  <-- Conflict ignored
$

Signed-off-by: David Meybohm <dmeybohmlkml@bellsouth.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
read-cache.c

index 34c040ad6c3bd3d2f2f4228ec2aefb9945e0ff84..bfdaee02ab4f25d39620e8d398f90ce27ed03805 100644 (file)
@@ -200,11 +200,13 @@ static int check_file_directory_conflict(const struct cache_entry *ce,
        cp = pathbuf;
        while (1) {
                char *ep = strchr(cp, '/');
+               int len;
                if (!ep)
                        break;
                *ep = 0;    /* first cut it at slash */
+               len = ep - pathbuf;
                pos = cache_name_pos(pathbuf,
-                                    htons(create_ce_flags(ep-cp, stage)));
+                                    htons(create_ce_flags(len, stage)));
                if (0 <= pos) {
                        /* Our leading path component is registered as a file,
                         * and we are trying to make it a directory.  This is