@@ -83,7 +83,7 @@ pub struct Config {
83
83
updated_sources : LazyCell < RefCell < HashSet < SourceId > > > ,
84
84
/// Lock, if held, of the global package cache along with the number of
85
85
/// acquisitions so far.
86
- package_cache_lock : RefCell < Option < ( FileLock , usize ) > > ,
86
+ package_cache_lock : RefCell < Option < ( Option < FileLock > , usize ) > > ,
87
87
}
88
88
89
89
impl Config {
@@ -887,28 +887,26 @@ impl Config {
887
887
// First, attempt to open an exclusive lock which is in general
888
888
// the purpose of this lock!
889
889
//
890
- // If that fails because of a readonly filesystem, though, then
891
- // we don't want to fail because it's a readonly filesystem. In
892
- // some situations Cargo is prepared to have a readonly
893
- // filesystem yet still work since it's all been pre-downloaded
894
- // and/or pre-unpacked. In these situations we want to keep
895
- // Cargo running if possible, so if it's a readonly filesystem
896
- // switch to a shared lock which should hopefully succeed so we
897
- // can continue.
890
+ // If that fails because of a readonly filesystem or a
891
+ // permission error, though, then we don't really want to fail
892
+ // just because of this. All files that this lock protects are
893
+ // in subfolders, so they're assumed by Cargo to also be
894
+ // readonly or have invalid permissions for us to write to. If
895
+ // that's the case, then we don't really need to grab a lock in
896
+ // the first place here.
898
897
//
899
- // Note that the package cache lock protects files in the same
900
- // directory, so if it's a readonly filesystem we assume that
901
- // the entire package cache is readonly, so we're just acquiring
902
- // something to prove it works, we're not actually doing any
903
- // synchronization at that point .
898
+ // Despite this we attempt to grab a readonly lock. This means
899
+ // that if our read-only folder is shared read-write with
900
+ // someone else on the system we should synchronize with them,
901
+ // but if we can't even do that then we did our best and we just
902
+ // keep on chugging elsewhere .
904
903
match self . home_path . open_rw ( path, self , desc) {
905
- Ok ( lock) => * slot = Some ( ( lock, 1 ) ) ,
904
+ Ok ( lock) => * slot = Some ( ( Some ( lock) , 1 ) ) ,
906
905
Err ( e) => {
907
906
if maybe_readonly ( & e) {
908
- if let Ok ( lock) = self . home_path . open_ro ( path, self , desc) {
909
- * slot = Some ( ( lock, 1 ) ) ;
910
- return Ok ( PackageCacheLock ( self ) ) ;
911
- }
907
+ let lock = self . home_path . open_ro ( path, self , desc) . ok ( ) ;
908
+ * slot = Some ( ( lock, 1 ) ) ;
909
+ return Ok ( PackageCacheLock ( self ) ) ;
912
910
}
913
911
914
912
Err ( e) . chain_err ( || "failed to acquire package cache lock" ) ?;
0 commit comments