mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 03:04:13 +03:00
Fix manifest update logic
This commit is contained in:
parent
beb4ed420f
commit
a036dc8ac3
@ -44,6 +44,6 @@ version = "1.3.0"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "manifest_refactors" ]
|
default = [ "manifest_refactors" ]
|
||||||
manifest_refactors = [ "manifest_refactor_remote", "manifest_refactor_project" ]
|
manifest_refactors = [ "manifest_refactor_project", "manifest_refactor_remote" ]
|
||||||
manifest_refactor_remote = [ ]
|
|
||||||
manifest_refactor_project = [ ]
|
manifest_refactor_project = [ ]
|
||||||
|
manifest_refactor_remote = [ ]
|
||||||
|
@ -128,18 +128,27 @@ impl TryFrom<&PathBuf> for Manifest {
|
|||||||
let mut old_remote_format: Option<&str> = None;
|
let mut old_remote_format: Option<&str> = None;
|
||||||
let mut new_remote_format_exists = false;
|
let mut new_remote_format_exists = false;
|
||||||
|
|
||||||
let mut new_toml = "".to_owned();
|
// Toml file adhering to the new format.
|
||||||
|
let mut final_toml = "".to_owned();
|
||||||
|
|
||||||
|
// New Toml file format that should be written based on feature flags.
|
||||||
|
let mut refactored_toml = "".to_owned();
|
||||||
|
|
||||||
// Read each individual line of the toml file
|
// Read each individual line of the toml file
|
||||||
for line in buffer.lines() {
|
for line in buffer.lines() {
|
||||||
// Determine if the old remote format is being used
|
// Determine if the old remote format is being used
|
||||||
#[cfg(feature = "manifest_refactor_remote")]
|
|
||||||
{
|
|
||||||
if line.starts_with("remote") {
|
if line.starts_with("remote") {
|
||||||
let remote = line
|
let remote = line
|
||||||
.split("=") // Split the line as 'remote' = '"{author}/{package_name}"'
|
.split("=") // Split the line as 'remote' = '"{author}/{package_name}"'
|
||||||
.collect::<Vec<&str>>()[1]; // Fetch just '"{author}/{package_name}"'
|
.collect::<Vec<&str>>()[1]; // Fetch just '"{author}/{package_name}"'
|
||||||
old_remote_format = Some(remote);
|
old_remote_format = Some(remote);
|
||||||
|
|
||||||
|
// Retain the old remote format if the `manifest_refactor_remote` is not enabled
|
||||||
|
#[cfg(not(feature = "manifest_refactor_remote"))]
|
||||||
|
{
|
||||||
|
refactored_toml += line;
|
||||||
|
refactored_toml += "\n";
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,24 +156,28 @@ impl TryFrom<&PathBuf> for Manifest {
|
|||||||
if line.starts_with("[remote]") {
|
if line.starts_with("[remote]") {
|
||||||
new_remote_format_exists = true;
|
new_remote_format_exists = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If the old project format is being being used, update the toml file
|
// If the old project format is being being used, update the toml file
|
||||||
// to use the new format instead.
|
// to use the new format instead.
|
||||||
|
if line.starts_with("[package]") {
|
||||||
|
final_toml += "[project]";
|
||||||
|
|
||||||
|
// Refactor the old project format if the `manifest_refactor_project` is enabled
|
||||||
#[cfg(feature = "manifest_refactor_project")]
|
#[cfg(feature = "manifest_refactor_project")]
|
||||||
{
|
{
|
||||||
if line.starts_with("[package]") {
|
refactored_toml += "[project]";
|
||||||
new_toml += "[project]";
|
|
||||||
} else {
|
|
||||||
new_toml += line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "manifest_refactor_project"))]
|
#[cfg(not(feature = "manifest_refactor_project"))]
|
||||||
{
|
{
|
||||||
new_toml += line;
|
refactored_toml += line;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final_toml += line;
|
||||||
|
refactored_toml += line;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_toml += "\n";
|
final_toml += "\n";
|
||||||
|
refactored_toml += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the remote format
|
// Update the remote format
|
||||||
@ -188,18 +201,24 @@ author = "{author}"
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Append the new remote to the bottom of the manifest file.
|
// Append the new remote to the bottom of the manifest file.
|
||||||
new_toml += &new_remote;
|
final_toml += &new_remote;
|
||||||
|
|
||||||
|
// Add the new remote format if the `manifest_refactor_remote` is enabled
|
||||||
|
#[cfg(feature = "manifest_refactor_remote")]
|
||||||
|
{
|
||||||
|
refactored_toml += &new_remote;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite the toml file if it has been updated
|
// Rewrite the toml file if it has been updated
|
||||||
if buffer != new_toml {
|
if buffer != refactored_toml {
|
||||||
let mut file = File::create(&path).map_err(|error| ManifestError::Creating(MANIFEST_FILENAME, error))?;
|
let mut file = File::create(&path).map_err(|error| ManifestError::Creating(MANIFEST_FILENAME, error))?;
|
||||||
file.write_all(new_toml.as_bytes())
|
file.write_all(refactored_toml.as_bytes())
|
||||||
.map_err(|error| ManifestError::Writing(MANIFEST_FILENAME, error))?;
|
.map_err(|error| ManifestError::Writing(MANIFEST_FILENAME, error))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the toml file
|
// Read the toml file
|
||||||
Ok(toml::from_str(&new_toml).map_err(|error| ManifestError::Parsing(MANIFEST_FILENAME, error))?)
|
Ok(toml::from_str(&final_toml).map_err(|error| ManifestError::Parsing(MANIFEST_FILENAME, error))?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user