@@ -4099,19 +4099,19 @@ static int remove_file(struct apply_state *state, struct patch *patch, int rmdir
4099
4099
return 0 ;
4100
4100
}
4101
4101
4102
- static void add_index_file (struct apply_state * state ,
4103
- const char * path ,
4104
- unsigned mode ,
4105
- void * buf ,
4106
- unsigned long size )
4102
+ static int add_index_file (struct apply_state * state ,
4103
+ const char * path ,
4104
+ unsigned mode ,
4105
+ void * buf ,
4106
+ unsigned long size )
4107
4107
{
4108
4108
struct stat st ;
4109
4109
struct cache_entry * ce ;
4110
4110
int namelen = strlen (path );
4111
4111
unsigned ce_size = cache_entry_size (namelen );
4112
4112
4113
4113
if (!state -> update_index )
4114
- return ;
4114
+ return 0 ;
4115
4115
4116
4116
ce = xcalloc (1 , ce_size );
4117
4117
memcpy (ce -> name , path , namelen );
@@ -4122,20 +4122,32 @@ static void add_index_file(struct apply_state *state,
4122
4122
const char * s ;
4123
4123
4124
4124
if (!skip_prefix (buf , "Subproject commit " , & s ) ||
4125
- get_sha1_hex (s , ce -> sha1 ))
4126
- die (_ ("corrupt patch for submodule %s" ), path );
4125
+ get_sha1_hex (s , ce -> sha1 )) {
4126
+ free (ce );
4127
+ return error (_ ("corrupt patch for submodule %s" ), path );
4128
+ }
4127
4129
} else {
4128
4130
if (!state -> cached ) {
4129
- if (lstat (path , & st ) < 0 )
4130
- die_errno (_ ("unable to stat newly created file '%s'" ),
4131
- path );
4131
+ if (lstat (path , & st ) < 0 ) {
4132
+ free (ce );
4133
+ return error (_ ("unable to stat newly "
4134
+ "created file '%s': %s" ),
4135
+ path , strerror (errno ));
4136
+ }
4132
4137
fill_stat_cache_info (ce , & st );
4133
4138
}
4134
- if (write_sha1_file (buf , size , blob_type , ce -> sha1 ) < 0 )
4135
- die (_ ("unable to create backing store for newly created file %s" ), path );
4139
+ if (write_sha1_file (buf , size , blob_type , ce -> sha1 ) < 0 ) {
4140
+ free (ce );
4141
+ return error (_ ("unable to create backing store "
4142
+ "for newly created file %s" ), path );
4143
+ }
4136
4144
}
4137
- if (add_cache_entry (ce , ADD_CACHE_OK_TO_ADD ) < 0 )
4138
- die (_ ("unable to add cache entry for %s" ), path );
4145
+ if (add_cache_entry (ce , ADD_CACHE_OK_TO_ADD ) < 0 ) {
4146
+ free (ce );
4147
+ return error (_ ("unable to add cache entry for %s" ), path );
4148
+ }
4149
+
4150
+ return 0 ;
4139
4151
}
4140
4152
4141
4153
static int try_create_file (const char * path , unsigned int mode , const char * buf , unsigned long size )
@@ -4271,8 +4283,10 @@ static void create_file(struct apply_state *state, struct patch *patch)
4271
4283
if (patch -> conflicted_threeway ) {
4272
4284
if (add_conflicted_stages_file (state , patch ))
4273
4285
exit (128 );
4274
- } else
4275
- add_index_file (state , path , mode , buf , size );
4286
+ } else {
4287
+ if (add_index_file (state , path , mode , buf , size ))
4288
+ exit (128 );
4289
+ }
4276
4290
}
4277
4291
4278
4292
/* phase zero is to remove, phase one is to create */
0 commit comments