crate: fix restoring original Cargo.toml for local projects

This commit is contained in:
Fabio Valentini 2023-10-09 23:28:18 +02:00
parent f579129792
commit 519f079729
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -155,12 +155,11 @@ def guess_local_project_version_from_path(project: str) -> tuple[str, str]:
@contextlib.contextmanager
def toml_temp_copy(toml_path: str):
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = f"{temp_dir}/Cargo.toml"
with open(temp_path, "w") as file:
with open(toml_path) as orig:
file.write(orig.read())
yield temp_path
with open(toml_path, "rb") as toml_file:
orig = toml_file.read()
yield
with open(toml_path, "wb") as toml_file:
toml_file.write(orig)
def process_project_local(
@ -199,14 +198,14 @@ def process_project_local(
version = package.version
features = package.get_feature_names()
with toml_temp_copy(toml_path) as temp_toml:
diffs = make_patches(name, package.version, patch, patch_foreign, temp_toml, features)
with toml_temp_copy(toml_path):
diffs = make_patches(name, package.version, patch, patch_foreign, toml_path, features)
# ensure metadata is up-to-date with changes from patches
metadata = Metadata.from_cargo(temp_toml)
metadata = Metadata.from_cargo(toml_path)
if vendor:
vendor_tarball = generate_vendor_tarball(temp_toml, name, package.version)
vendor_tarball = generate_vendor_tarball(toml_path, name, package.version)
else:
vendor_tarball = None