git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Troubles when directory is replaced by symlink

From
KBKjetil Barvik <barvik@broadpark.no>
Date
Jun 14, 2009, 14:34 UTC
Message-ID
<861vpmkhob.fsf@broadpark.no>
In-Reply-To
<20090611114846.GC4409@coredump.intra.peff.net>
From: Kjetil Barvik <barvik@broadpark.no>
Date: Sun, 14 Jun 2009 15:08:28 +0200
Subject: [PATCH] lstat_cache: guard against full match of length of 'name' parameter

longest_path_match() in symlinks.c does exactly what it's name says, but in some cases that match can be too long, since the has_*_leading_path() functions assumes that the match will newer be as long as the name string given to the function.

fix this by adding an extra if test which checks if the match length is equal to the 'len' parameter. ---

  OK, this is a first version of a patch for this bug.  I have not added
  a "Signed-off-by:"-tag yet, but I intend to do that when I am more
  shure that this is the real fix for the bug.  Will also add a test
  case in a later version.
  The given instructions(1) to repeat the failure, gave me the following
  4 calls to has_symlink_leading_path() for the failed 'git checkout
  master' command, and I made the following the table:
   'name' parameter       Kjetil      Linus      tested
  -------------------------------------------------------
   "beta/alpha/file"        2           1           2
   "beta/alpha"             2C          0           0
   "alpha/file"             0           0           0
   "beta/alpha/file"        0           1C          0
  The "Kjetil" column is what the h_s_l_p() function returns as of
  commit 92604b46 by me.  The "Linus" column is what the h_s_l_p()
  function returns as of commit c40641b7 by Linus.  The "tested" column
  is what will be returned when the cache is clear'ed each time.  An
  added "C" indicate that the result was cached/taken from the cache.
  My bug is from the incorrect cached value from line 2, and since I
  noticed that it take the symbolic link result, "beta/alpha", which was
  the full length of the 'name' parameter and not the leading part, I
  have based the included patch on this fact.
  The function is named has_symlink_leading_path(), so I guess it is a
  reason for that "leading" part of the name.  So, is this a reasonable
  fix?  Other comments?
  -- kjetil
  1) the following commands:

# make a repo mkdir repo && cd repo && git init

# content in alpha mkdir alpha && echo content >alpha/file && git add . && git commit -m one # and duplicate content inside beta mkdir beta && cp -R alpha beta && git add . && git commit -m two

# now replace the duplicate with a symlink git checkout -b branch rm -rf beta/alpha && git add -u && git commit -m deleted ln -s ../alpha beta/alpha && git add . && git commit -m symlink

# now checkout master again; alpha/file will be missing, even # though it wasn't touched at all git checkout master

 symlinks.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/symlinks.c b/symlinks.c
index 8dcd632..934abc6 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -97,6 +97,10 @@ static int lstat_cache(const char *name, int len,
 			longest_path_match(name, len, cache.path, cache.len,
 					   &previous_slash);
 		match_flags = cache.flags & track_flags & (FL_NOENT|FL_SYMLINK);
+
+		if (!(track_flags & FL_FULLPATH) && match_len == len)
+			match_len = last_slash = previous_slash;
+
 		if (match_flags && match_len == cache.len)
 			return match_flags;
 		/*
-- 
1.6.3.2.277.gd10543
Previous: Kjetil BarvikNext: James Pickens
Message 5 of 9 in “Troubles when directory is replaced by symlink”
  1. Alexander GladyshJun 5, 2009
  2. Alexander GladyshJun 9, 2009
  3. Jeff KingJun 11, 2009
  4. Kjetil BarvikJun 11, 2009
  5. Kjetil BarvikJun 14, 2009
  6. James PickensJun 24, 2009
  7. Kjetil BarvikJun 25, 2009
  8. Kjetil BarvikJun 26, 2009
  9. Johannes SixtJun 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.