@@ -164,7 +164,10 @@ impl Filesystem {
164164 let mut opts = OpenOptions :: new ( ) ;
165165 opts. read ( true ) . write ( true ) . create ( true ) ;
166166 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 } )
168171 }
169172
170173 /// A non-blocking version of [`Filesystem::open_rw`].
@@ -196,7 +199,10 @@ impl Filesystem {
196199 P : AsRef < Path > ,
197200 {
198201 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 } )
200206 }
201207
202208 /// Opens shared access to a file, returning the locked version of a file.
@@ -212,7 +218,10 @@ impl Filesystem {
212218 let mut opts = OpenOptions :: new ( ) ;
213219 opts. read ( true ) . write ( true ) . create ( true ) ;
214220 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 } )
216225 }
217226
218227 /// A non-blocking version of [`Filesystem::open_shared_create`].
@@ -248,26 +257,6 @@ impl Filesystem {
248257 . with_context ( || format ! ( "failed to open: {}" , path. display( ) ) ) ?;
249258 Ok ( ( path, f) )
250259 }
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- }
271260}
272261
273262impl PartialEq < Path > for Filesystem {
0 commit comments