diff --git a/rust2rpm/crate.py b/rust2rpm/crate.py index 305587b..bc7e4fb 100644 --- a/rust2rpm/crate.py +++ b/rust2rpm/crate.py @@ -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