File tree 1 file changed +13
-0
lines changed
src/cargo/sources/registry
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,19 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
116
116
-> CargoResult < FileLock > {
117
117
let filename = format ! ( "{}-{}.crate" , pkg. name( ) , pkg. version( ) ) ;
118
118
let path = Path :: new ( & filename) ;
119
+
120
+ // Attempt to open an read-only copy first to avoid an exclusive write
121
+ // lock and also work with read-only filesystems. Note that we check the
122
+ // length of the file like below to handle interrupted downloads.
123
+ //
124
+ // If this fails then we fall through to the exclusive path where we may
125
+ // have to redownload the file.
126
+ if let Ok ( dst) = self . cache_path . open_ro ( path, self . config , & filename) {
127
+ let meta = try!( dst. file ( ) . metadata ( ) ) ;
128
+ if meta. len ( ) > 0 {
129
+ return Ok ( dst)
130
+ }
131
+ }
119
132
let mut dst = try!( self . cache_path . open_rw ( path, self . config , & filename) ) ;
120
133
let meta = try!( dst. file ( ) . metadata ( ) ) ;
121
134
if meta. len ( ) > 0 {
You can’t perform that action at this time.
0 commit comments