@@ -253,6 +253,7 @@ static int write_entry(struct cache_entry *ce,
253253 char * path , const struct checkout * state , int to_tempfile )
254254{
255255 unsigned int ce_mode_s_ifmt = ce -> ce_mode & S_IFMT ;
256+ struct delayed_checkout * dco = state -> delayed_checkout ;
256257 int fd , ret , fstat_done = 0 ;
257258 char * new ;
258259 struct strbuf buf = STRBUF_INIT ;
@@ -273,55 +274,65 @@ static int write_entry(struct cache_entry *ce,
273274 }
274275
275276 switch (ce_mode_s_ifmt ) {
276- case S_IFREG :
277277 case S_IFLNK :
278278 new = read_blob_entry (ce , & size );
279279 if (!new )
280280 return error ("unable to read sha1 file of %s (%s)" ,
281- path , oid_to_hex (& ce -> oid ));
281+ path , oid_to_hex (& ce -> oid ));
282282
283- if (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile ) {
284- ret = symlink (new , path );
285- free (new );
286- if (ret )
287- return error_errno ("unable to create symlink %s" ,
288- path );
289- break ;
283+ /*
284+ * We can't make a real symlink; write out a regular file entry
285+ * with the symlink destination as its contents.
286+ */
287+ if (!has_symlinks || to_tempfile )
288+ goto write_file_entry ;
289+
290+ ret = symlink (new , path );
291+ free (new );
292+ if (ret )
293+ return error_errno ("unable to create symlink %s" , path );
294+ break ;
295+
296+ case S_IFREG :
297+ /*
298+ * We do not send the blob in case of a retry, so do not
299+ * bother reading it at all.
300+ */
301+ if (dco && dco -> state == CE_RETRY ) {
302+ new = NULL ;
303+ size = 0 ;
304+ } else {
305+ new = read_blob_entry (ce , & size );
306+ if (!new )
307+ return error ("unable to read sha1 file of %s (%s)" ,
308+ path , oid_to_hex (& ce -> oid ));
290309 }
291310
292311 /*
293312 * Convert from git internal format to working tree format
294313 */
295- if (ce_mode_s_ifmt == S_IFREG ) {
296- struct delayed_checkout * dco = state -> delayed_checkout ;
297- if (dco && dco -> state != CE_NO_DELAY ) {
298- /* Do not send the blob in case of a retry. */
299- if (dco -> state == CE_RETRY ) {
300- new = NULL ;
301- size = 0 ;
302- }
303- ret = async_convert_to_working_tree (
304- ce -> name , new , size , & buf , dco );
305- if (ret && string_list_has_string (& dco -> paths , ce -> name )) {
306- free (new );
307- goto finish ;
308- }
309- } else
310- ret = convert_to_working_tree (
311- ce -> name , new , size , & buf );
312-
313- if (ret ) {
314+ if (dco && dco -> state != CE_NO_DELAY ) {
315+ ret = async_convert_to_working_tree (ce -> name , new ,
316+ size , & buf , dco );
317+ if (ret && string_list_has_string (& dco -> paths , ce -> name )) {
314318 free (new );
315- new = strbuf_detach (& buf , & newsize );
316- size = newsize ;
319+ goto delayed ;
317320 }
318- /*
319- * No "else" here as errors from convert are OK at this
320- * point. If the error would have been fatal (e.g.
321- * filter is required), then we would have died already.
322- */
321+ } else
322+ ret = convert_to_working_tree (ce -> name , new , size , & buf );
323+
324+ if (ret ) {
325+ free (new );
326+ new = strbuf_detach (& buf , & newsize );
327+ size = newsize ;
323328 }
329+ /*
330+ * No "else" here as errors from convert are OK at this
331+ * point. If the error would have been fatal (e.g.
332+ * filter is required), then we would have died already.
333+ */
324334
335+ write_file_entry :
325336 fd = open_output_fd (path , ce , to_tempfile );
326337 if (fd < 0 ) {
327338 free (new );
@@ -336,6 +347,7 @@ static int write_entry(struct cache_entry *ce,
336347 if (wrote < 0 )
337348 return error ("unable to write file %s" , path );
338349 break ;
350+
339351 case S_IFGITLINK :
340352 if (to_tempfile )
341353 return error ("cannot create temporary submodule %s" , path );
@@ -347,6 +359,7 @@ static int write_entry(struct cache_entry *ce,
347359 NULL , oid_to_hex (& ce -> oid ),
348360 state -> force ? SUBMODULE_MOVE_HEAD_FORCE : 0 );
349361 break ;
362+
350363 default :
351364 return error ("unknown file mode for %s in index" , path );
352365 }
@@ -355,11 +368,14 @@ static int write_entry(struct cache_entry *ce,
355368 if (state -> refresh_cache ) {
356369 assert (state -> istate );
357370 if (!fstat_done )
358- lstat (ce -> name , & st );
371+ if (lstat (ce -> name , & st ) < 0 )
372+ return error_errno ("unable to stat just-written file %s" ,
373+ ce -> name );
359374 fill_stat_cache_info (ce , & st );
360375 ce -> ce_flags |= CE_UPDATE_IN_BASE ;
361376 state -> istate -> cache_changed |= CE_ENTRY_CHANGED ;
362377 }
378+ delayed :
363379 return 0 ;
364380}
365381
0 commit comments