File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ static struct dirtree *dirtree_handle_callback(struct dirtree *new,
125
125
flags = callback (new );
126
126
127
127
if (S_ISDIR (new -> st .st_mode ) && (flags & df )) {
128
+ // TODO: check openat returned fd for errors... and do what about it?
128
129
if (* new -> name ) fd = openat (dirtree_parentfd (new ), new -> name , O_CLOEXEC );
129
130
if (flags & DIRTREE_BREADTH ) {
130
131
new -> again |= DIRTREE_BREADTH ;
@@ -133,10 +134,11 @@ static struct dirtree *dirtree_handle_callback(struct dirtree *new,
133
134
return DIRTREE_ABORTVAL ;
134
135
}
135
136
flags = dirtree_recurse (new , callback , fd , flags );
137
+ close (fd );
136
138
}
137
139
138
140
// Free node that didn't request saving and has no saved children.
139
- if (!new -> child && !(flags & DIRTREE_SAVE ) && (! new -> parent || !( new -> parent -> again & DIRTREE_BREADTH )) ) {
141
+ if (!new -> child && !(flags & DIRTREE_SAVE )) {
140
142
free (new );
141
143
new = 0 ;
142
144
}
@@ -145,7 +147,7 @@ static struct dirtree *dirtree_handle_callback(struct dirtree *new,
145
147
}
146
148
147
149
// Recursively read/process children of directory node, filtering through
148
- // callback(). Uses and closes supplied ->dirfd.
150
+ // callback().
149
151
150
152
int dirtree_recurse (struct dirtree * node ,
151
153
int (* callback )(struct dirtree * node ), int dirfd , int flags )
Original file line number Diff line number Diff line change @@ -287,7 +287,7 @@ static int add_to_tar(struct dirtree *node)
287
287
free (name );
288
288
289
289
return DIRTREE_BREADTH ;
290
- } else if (node -> again & DIRTREE_BREADTH ) {
290
+ } else if (( node -> again & DIRTREE_BREADTH ) && node -> child ) {
291
291
struct dirtree * dt , * * sort = xmalloc (sizeof (void * )* node -> extra );
292
292
293
293
for (node -> extra = 0 , dt = node -> child ; dt ; dt = dt -> next )
You can’t perform that action at this time.
0 commit comments