Skip to content

Commit 971f229

Browse files
torvaldsgitster
authored andcommitted
Fix possible Solaris problem in 'checkout_entry()'
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>
1 parent c4758d3 commit 971f229

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

entry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
218218
* to emulate by hand - much easier to let the system
219219
* just do the right thing)
220220
*/
221-
unlink(path);
222221
if (S_ISDIR(st.st_mode)) {
223222
/* If it is a gitlink, leave it alone! */
224223
if (S_ISGITLINK(ce->ce_mode))
225224
return 0;
226225
if (!state->force)
227226
return error("%s is a directory", path);
228227
remove_subtree(path);
229-
}
228+
} else if (unlink(path))
229+
return error("unable to unlink old '%s' (%s)", path, strerror(errno));
230230
} else if (state->not_new)
231231
return 0;
232232
create_directories(path, state);

0 commit comments

Comments
 (0)