Skip to content

Commit

Permalink
Fix possible Solaris problem in 'checkout_entry()'
Browse files Browse the repository at this point in the history
Currently when checking out an entry "path", we try to unlink(2) it first
(because there could be stale file), and if there is a directory there,
try to deal with it (typically we run recursive rmdir).  We ignore the
error return from this unlink because there may not even be any file
there.

However if you are root on Solaris, you can unlink(2) a directory
successfully and corrupt your filesystem.

This moves the code around and check the directory first, and then
unlink(2).  Also we check the error code from it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
torvalds authored and gitster committed Mar 19, 2008
1 parent c4758d3 commit 971f229
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
* to emulate by hand - much easier to let the system
* just do the right thing)
*/
unlink(path);
if (S_ISDIR(st.st_mode)) {
/* If it is a gitlink, leave it alone! */
if (S_ISGITLINK(ce->ce_mode))
return 0;
if (!state->force)
return error("%s is a directory", path);
remove_subtree(path);
}
} else if (unlink(path))
return error("unable to unlink old '%s' (%s)", path, strerror(errno));
} else if (state->not_new)
return 0;
create_directories(path, state);
Expand Down

0 comments on commit 971f229

Please sign in to comment.