Skip to content

Commit 9f83b3c

Browse files
committed
Check for source in resolution as well
1 parent b389338 commit 9f83b3c

File tree

6 files changed

+51
-30
lines changed

6 files changed

+51
-30
lines changed

src/http.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::fs::untar_archive;
77
use ureq::http::{HeaderName, HeaderValue};
88
use ureq::Agent;
99

10-
use ureq::tls::{TlsConfig, RootCerts};
10+
use ureq::tls::{RootCerts, TlsConfig};
1111

1212
/// Downloads a remote content to the given writer.
1313
/// Returns the number of bytes written to the writer, 0 for a 404 or an empty 200
@@ -16,18 +16,17 @@ pub fn download<W: Write>(
1616
writer: &mut W,
1717
headers: Vec<(&str, String)>,
1818
) -> Result<u64, HttpError> {
19-
2019
let agent = Agent::config_builder()
21-
.tls_config(
22-
TlsConfig::builder()
23-
.root_certs(RootCerts::PlatformVerifier)
24-
.build()
25-
)
26-
.timeout_global(Some(Duration::from_secs(200)))
27-
.build()
28-
.new_agent();
29-
30-
let mut request_builder = agent.get(url);
20+
.tls_config(
21+
TlsConfig::builder()
22+
.root_certs(RootCerts::PlatformVerifier)
23+
.build(),
24+
)
25+
.timeout_global(Some(Duration::from_secs(200)))
26+
.build()
27+
.new_agent();
28+
29+
let mut request_builder = agent.get(url);
3130

3231
{
3332
let req_headers = request_builder.headers_mut().unwrap();

src/lockfile.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ impl Source {
157157
(
158158
Source::Repository { repository: r1 },
159159
ConfigDependency::Detailed { repository: r2, .. },
160-
) => Some(r1) == r2.as_ref(),
160+
) => {
161+
// We are only comparing the repositories here
162+
if let Some(r) = r2 {
163+
r == r1
164+
} else {
165+
true
166+
}
167+
},
161168
(Source::Repository { .. }, ConfigDependency::Simple(..)) => true,
162169
_ => false,
163170
}
@@ -302,6 +309,23 @@ impl LockedPackage {
302309
pub fn install_suggests(&self) -> bool {
303310
!self.suggests.is_empty()
304311
}
312+
313+
pub fn is_matching(&self, dep: &ConfigDependency, repo_urls: &HashSet<&str>) -> bool {
314+
if dep.install_suggestions() && !self.install_suggests() {
315+
return false;
316+
}
317+
318+
match self.source {
319+
Source::Repository { ref repository } => {
320+
if !repo_urls.contains(repository.as_str()) {
321+
return false;
322+
}
323+
}
324+
_ => (),
325+
}
326+
327+
true
328+
}
305329
}
306330

307331
#[derive(Debug, Deserialize, Clone, PartialEq)]
@@ -416,7 +440,7 @@ impl Lockfile {
416440
) -> Option<&LockedPackage> {
417441
if let Some(p) = self.packages.iter().find(|p| p.name == name) {
418442
if let Some(d) = dep {
419-
if p.source.is_matching(d) && p.install_suggests() == d.install_suggestions() {
443+
if p.source.is_matching(d) {
420444
return Some(p);
421445
}
422446
} else {
@@ -449,17 +473,9 @@ impl Lockfile {
449473
let repo_urls = repos.iter().map(|x| x.url()).collect::<HashSet<_>>();
450474
for d in deps {
451475
if let Some(pkg) = self.get_package(d.name(), Some(d)) {
452-
if d.install_suggestions() && !pkg.install_suggests() {
476+
if !pkg.is_matching(d, &repo_urls) {
453477
return false;
454478
}
455-
match pkg.source {
456-
Source::Repository { ref repository } => {
457-
if !repo_urls.contains(repository.as_str()) {
458-
return false;
459-
}
460-
}
461-
_ => ()
462-
}
463479
} else {
464480
return false;
465481
}

src/resolver/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ impl<'d> Resolver<'d> {
377377
) -> Resolution<'d> {
378378
let mut result = Resolution::default();
379379
let mut processed = HashSet::with_capacity(dependencies.len() * 10);
380+
let repo_urls = self
381+
.repositories
382+
.iter()
383+
.map(|(x, _)| x.url.as_str())
384+
.collect::<HashSet<_>>();
380385
let mut queue: VecDeque<_> = dependencies
381386
.iter()
382387
.map(|d| QueueItem {
@@ -388,9 +393,10 @@ impl<'d> Resolver<'d> {
388393
parent: None,
389394
remote: None,
390395
local_path: d.local_path(),
391-
matching_in_lockfile: self
392-
.lockfile
393-
.map(|l| l.get_package(d.name(), Some(d)).is_some()),
396+
matching_in_lockfile: self.lockfile.and_then(|l| {
397+
l.get_package(d.name(), Some(d))
398+
.map(|p| p.is_matching(d, &repo_urls))
399+
}),
394400
})
395401
.collect();
396402

@@ -657,7 +663,7 @@ mod tests {
657663
}
658664
res
659665
} else {
660-
let mut repo = RepositoryDatabase::new("");
666+
let mut repo = RepositoryDatabase::new("http://cran");
661667
repo.parse_source(parts[1]);
662668
vec![(repo, false)]
663669
};

src/resolver/snapshots/rv__resolver__tests__simple_no_lockfile.txt.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: src/resolver/mod.rs
33
expression: out
44
---
5-
R6=2.5.1 (repository(url: ), type=source, path='', from_lockfile=false, from_remote=false)
5+
R6=2.5.1 (repository(url: http://cran), type=source, path='', from_lockfile=false, from_remote=false)

src/resolver/snapshots/rv__resolver__tests__unmet_version_req.txt.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
source: src/resolver/mod.rs
33
expression: out
44
---
5-
unmet-version-req=0.0.1 (repository(url: ), type=source, path='', from_lockfile=false, from_remote=false)
5+
unmet-version-req=0.0.1 (repository(url: http://cran), type=source, path='', from_lockfile=false, from_remote=false)
66
--- unresolved ---
77
zzlite (>= 1.0) [required by: unmet-version-req]

src/tests/resolution/suggestions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "test"
33
r_version = "4.4"
44
repositories = []
55
# The lockfile is generated without install_suggestions = true
6-
# so a new call to the resolution should
6+
# so a new call to the resolution should invalidate the lockfile
77
dependencies = [
88
{ name = "A3", install_suggestions = true }
99
]

0 commit comments

Comments
 (0)