[core] Extract `RUNTIME_ENVIRONMENT` parsing logic into a function.
This is a method-extraction refactoring which pulls out the logic needed
to parse `RUNTIME_ENVIRONMENT` metafiles.
(Note: this is used for a future change that also needs this logic).
@@ -464,11 +464,7 @@ impl PackageInstall {
Ok(paths)
}
- /// Return the embedded runtime environment specification for a
- /// package.
- pub fn runtime_environment(&self) -> Result<HashMap<String, String>> {
- match self.read_metafile(MetaFile::RuntimeEnvironment) {
- Ok(body) => {
+ fn parse_runtime_environment_metafile(body: &str) -> Result<HashMap<String, String>> {
let mut env = HashMap::new();
for line in body.lines() {
let parts: Vec<&str> = line.splitn(2, "=").collect();
@@ -481,6 +477,12 @@ impl PackageInstall {
}
Ok(env)
}
+
+ /// Return the embedded runtime environment specification for a
+ /// package.
+ pub fn runtime_environment(&self) -> Result<HashMap<String, String>> {
+ match self.read_metafile(MetaFile::RuntimeEnvironment) {
+ Ok(ref body) => Self::parse_runtime_environment_metafile(body),
Err(Error::MetaFileNotFound(MetaFile::RuntimeEnvironment)) => {
// If there was no RUNTIME_ENVIRONMENT, we can at
// least return a proper PATH
