-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
A-cargo-apiArea: cargo-the-library API and internal code issuesArea: cargo-the-library API and internal code issuesA-filesystemArea: issues with filesystemsArea: issues with filesystemsC-bugCategory: bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review
Description
Problem
cargo::ops::package creates a tarball of a crate for publishing/uploading purposes. It returns a cargo::util::FileLock that should point to the generated tarball. In fact, it points to the scratch file that cargo uses to write the tarball, but this scratch file is deleted before the function ends.
Steps
This code illustrates the bug:
use cargo::core::{shell::Shell, Workspace};
use cargo::ops::PackageOpts;
use cargo::util::config;
use cargo::util::config::Config;
use std::env;
fn main() {
let dir = env::current_dir().unwrap();
let homedir = config::homedir(&dir).unwrap();
let config = Config::new(Shell::new(), dir.clone(), homedir.clone());
let workspace = Workspace::new(&dir.join("Cargo.toml"), &config).unwrap();
let x = cargo::ops::package(
&workspace,
&PackageOpts {
config: &config,
list: false,
check_metadata: false,
allow_dirty: true,
verify: false,
jobs: None,
target: None,
features: Vec::new(),
all_features: false,
no_default_features: false,
},
)
.unwrap()
.unwrap();
let path = x.path();
println!("Path = {}", path.display());
println!("Exists = {}", path.exists());
}
Expectation
The path returned by ops::package should exist
Reality
The returned path is deleted before the function returns
Possible Solution(s)
Replace the path
field on the FileLock
before package
returns at the time the file is renamed.
cargo/src/cargo/ops/cargo_package.rs
Line 135 in 972b9f5
fs::rename(&src_path, &dst_path) |
Notes
Output of cargo version
:
libcargo 1.42.0
Metadata
Metadata
Assignees
Labels
A-cargo-apiArea: cargo-the-library API and internal code issuesArea: cargo-the-library API and internal code issuesA-filesystemArea: issues with filesystemsArea: issues with filesystemsC-bugCategory: bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review