Skip to content

Commit

Permalink
Be more careful about tree entry modes.
Browse files Browse the repository at this point in the history
The tree object parsing used to get the executable bit wrong,
and didn't know about symlinks. Also, fsck really wants the
full mode value so that it can verify the other bits for sanity,
so save it all in struct tree_entry.
  • Loading branch information
Linus Torvalds committed May 5, 2005
1 parent d5a72fd commit 42ea9cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions fsck-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ static int fsck_tree(struct tree *item)
if (strchr(entry->name, '/'))
has_full_path = 1;

switch (entry->mode) {
/*
* Standard modes..
*/
case S_IFREG | 0755:
case S_IFREG | 0644:
case S_IFLNK:
case S_IFDIR:
break;
/*
* This is nonstandard, but we had a few of these
* early on when we honored the full set of mode
* bits..
*/
case S_IFREG | 0664:
break;
default:
printf("tree %s has entry %o %s\n",
sha1_to_hex(item->object.sha1),
entry->mode, entry->name);
}

if (last) {
if (verify_ordered(last, entry) < 0) {
fprintf(stderr, "tree %s not ordered\n",
Expand Down
6 changes: 4 additions & 2 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ int parse_tree(struct tree *item)

entry = xmalloc(sizeof(struct tree_entry_list));
entry->name = strdup(path + 1);
entry->directory = S_ISDIR(mode);
entry->executable = mode & S_IXUSR;
entry->directory = S_ISDIR(mode) != 0;
entry->executable = (mode & S_IXUSR) != 0;
entry->symlink = S_ISLNK(mode) != 0;
entry->mode = mode;
entry->next = NULL;

bufptr += len + 20;
Expand Down
2 changes: 2 additions & 0 deletions tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct tree_entry_list {
struct tree_entry_list *next;
unsigned directory : 1;
unsigned executable : 1;
unsigned symlink : 1;
unsigned int mode;
char *name;
union {
struct tree *tree;
Expand Down

0 comments on commit 42ea9cb

Please sign in to comment.