@@ -164,7 +164,10 @@ impl Filesystem {
164
164
let mut opts = OpenOptions :: new ( ) ;
165
165
opts. read ( true ) . write ( true ) . create ( true ) ;
166
166
let ( path, f) = self . open ( path. as_ref ( ) , & opts, true ) ?;
167
- self . lock ( path, f, config, msg, true )
167
+ acquire ( config, msg, & path, & || try_lock_exclusive ( & f) , & || {
168
+ lock_exclusive ( & f)
169
+ } ) ?;
170
+ Ok ( FileLock { f : Some ( f) , path } )
168
171
}
169
172
170
173
/// A non-blocking version of [`Filesystem::open_rw`].
@@ -196,7 +199,10 @@ impl Filesystem {
196
199
P : AsRef < Path > ,
197
200
{
198
201
let ( path, f) = self . open ( path. as_ref ( ) , & OpenOptions :: new ( ) . read ( true ) , false ) ?;
199
- self . lock ( path, f, config, msg, false )
202
+ acquire ( config, msg, & path, & || try_lock_shared ( & f) , & || {
203
+ lock_shared ( & f)
204
+ } ) ?;
205
+ Ok ( FileLock { f : Some ( f) , path } )
200
206
}
201
207
202
208
/// Opens shared access to a file, returning the locked version of a file.
@@ -212,7 +218,10 @@ impl Filesystem {
212
218
let mut opts = OpenOptions :: new ( ) ;
213
219
opts. read ( true ) . write ( true ) . create ( true ) ;
214
220
let ( path, f) = self . open ( path. as_ref ( ) , & opts, true ) ?;
215
- self . lock ( path, f, config, msg, false )
221
+ acquire ( config, msg, & path, & || try_lock_shared ( & f) , & || {
222
+ lock_shared ( & f)
223
+ } ) ?;
224
+ Ok ( FileLock { f : Some ( f) , path } )
216
225
}
217
226
218
227
/// A non-blocking version of [`Filesystem::open_shared_create`].
@@ -248,26 +257,6 @@ impl Filesystem {
248
257
. with_context ( || format ! ( "failed to open: {}" , path. display( ) ) ) ?;
249
258
Ok ( ( path, f) )
250
259
}
251
-
252
- fn lock (
253
- & self ,
254
- path : PathBuf ,
255
- f : File ,
256
- config : & Config ,
257
- msg : & str ,
258
- exclusive : bool ,
259
- ) -> CargoResult < FileLock > {
260
- if exclusive {
261
- acquire ( config, msg, & path, & || try_lock_exclusive ( & f) , & || {
262
- lock_exclusive ( & f)
263
- } ) ?;
264
- } else {
265
- acquire ( config, msg, & path, & || try_lock_shared ( & f) , & || {
266
- lock_shared ( & f)
267
- } ) ?;
268
- }
269
- Ok ( FileLock { f : Some ( f) , path } )
270
- }
271
260
}
272
261
273
262
impl PartialEq < Path > for Filesystem {
0 commit comments