@@ -121,15 +121,17 @@ static char *resolve_symlink(char *p, size_t s)
121121}
122122
123123
124- static int lock_file (struct lock_file * lk , const char * path )
124+ static int lock_file (struct lock_file * lk , const char * path , int flags )
125125{
126- if (strlen (path ) >= sizeof (lk -> filename )) return -1 ;
126+ if (strlen (path ) >= sizeof (lk -> filename ))
127+ return -1 ;
127128 strcpy (lk -> filename , path );
128129 /*
129130 * subtract 5 from size to make sure there's room for adding
130131 * ".lock" for the lock file name
131132 */
132- resolve_symlink (lk -> filename , sizeof (lk -> filename )- 5 );
133+ if (!(flags & LOCK_NODEREF ))
134+ resolve_symlink (lk -> filename , sizeof (lk -> filename )- 5 );
133135 strcat (lk -> filename , ".lock" );
134136 lk -> fd = open (lk -> filename , O_RDWR | O_CREAT | O_EXCL , 0666 );
135137 if (0 <= lk -> fd ) {
@@ -155,35 +157,35 @@ static int lock_file(struct lock_file *lk, const char *path)
155157 return lk -> fd ;
156158}
157159
158- int hold_lock_file_for_update (struct lock_file * lk , const char * path , int die_on_error )
160+ int hold_lock_file_for_update (struct lock_file * lk , const char * path , int flags )
159161{
160- int fd = lock_file (lk , path );
161- if (fd < 0 && die_on_error )
162+ int fd = lock_file (lk , path , flags );
163+ if (fd < 0 && ( flags & LOCK_DIE_ON_ERROR ) )
162164 die ("unable to create '%s.lock': %s" , path , strerror (errno ));
163165 return fd ;
164166}
165167
166- int hold_lock_file_for_append (struct lock_file * lk , const char * path , int die_on_error )
168+ int hold_lock_file_for_append (struct lock_file * lk , const char * path , int flags )
167169{
168170 int fd , orig_fd ;
169171
170- fd = lock_file (lk , path );
172+ fd = lock_file (lk , path , flags );
171173 if (fd < 0 ) {
172- if (die_on_error )
174+ if (flags & LOCK_DIE_ON_ERROR )
173175 die ("unable to create '%s.lock': %s" , path , strerror (errno ));
174176 return fd ;
175177 }
176178
177179 orig_fd = open (path , O_RDONLY );
178180 if (orig_fd < 0 ) {
179181 if (errno != ENOENT ) {
180- if (die_on_error )
182+ if (flags & LOCK_DIE_ON_ERROR )
181183 die ("cannot open '%s' for copying" , path );
182184 close (fd );
183185 return error ("cannot open '%s' for copying" , path );
184186 }
185187 } else if (copy_fd (orig_fd , fd )) {
186- if (die_on_error )
188+ if (flags & LOCK_DIE_ON_ERROR )
187189 exit (128 );
188190 close (fd );
189191 return -1 ;
@@ -215,7 +217,10 @@ int commit_lock_file(struct lock_file *lk)
215217
216218int hold_locked_index (struct lock_file * lk , int die_on_error )
217219{
218- return hold_lock_file_for_update (lk , get_index_file (), die_on_error );
220+ return hold_lock_file_for_update (lk , get_index_file (),
221+ die_on_error
222+ ? LOCK_DIE_ON_ERROR
223+ : 0 );
219224}
220225
221226void set_alternate_index_output (const char * name )
0 commit comments