Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::fs::{self, File};
use std::fs::File;
use std::io::SeekFrom;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -160,11 +160,8 @@ fn create_package(
}

let filename = pkg.package_id().tarball_name();
let dir = ws.build_dir().join("package");
let mut dst = {
let tmp = format!(".{}", filename);
dir.open_rw_exclusive_create(&tmp, gctx, "package scratch space")?
};
let dir = ws.build_dir().join("package").join("tmp-crate");
let dst = dir.open_rw_exclusive_create(&filename, gctx, "package scratch space")?;
Comment on lines +163 to +164
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this will cause a behavior change, Ive marked this as a draft while we wait for #15910 to propagate to users so they can prepare.


// Package up and test a temporary tarball and only move it to the final
// location if it actually passes all our tests. Any previously existing
Expand All @@ -176,16 +173,10 @@ fn create_package(
let uncompressed_size = tar(ws, opts, pkg, local_reg, ar_files, dst.file(), &filename)
.context("failed to prepare local package for uploading")?;

dst.seek(SeekFrom::Start(0))?;
let src_path = dst.path();
let dst_path = dst.parent().join(&filename);
fs::rename(&src_path, &dst_path)
.context("failed to move temporary tarball into final location")?;

let dst_metadata = dst
.file()
.metadata()
.with_context(|| format!("could not learn metadata for: `{}`", dst_path.display()))?;
.with_context(|| format!("could not learn metadata for: `{}`", dst.path().display()))?;
let compressed_size = dst_metadata.len();

let uncompressed = HumanBytes(uncompressed_size);
Expand Down Expand Up @@ -219,22 +210,22 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi

let packaged = do_package(ws, opts, pkgs)?;

// Uplifting artifacts
let mut result = Vec::new();
let target_dir = ws.target_dir();
let build_dir = ws.build_dir();
if target_dir == build_dir {
result.extend(packaged.into_iter().map(|(_, _, src)| src));
} else {
// Uplifting artifacts
let artifact_dir = target_dir.join("package");
for (pkg, _, src) in packaged {
let filename = pkg.package_id().tarball_name();
let dst =
artifact_dir.open_rw_exclusive_create(filename, ws.gctx(), "uplifted package")?;
src.file().seek(SeekFrom::Start(0))?;
std::io::copy(&mut src.file(), &mut dst.file())?;
result.push(dst);
}
let artifact_dir = ws.target_dir().join("package");
for (pkg, _, src) in packaged {
let filename = pkg.package_id().tarball_name();

let tmp = format!(".{filename}");
let dst = artifact_dir.open_rw_exclusive_create(tmp, ws.gctx(), "uplifted package")?;
src.file().seek(SeekFrom::Start(0))?;
std::io::copy(&mut src.file(), &mut dst.file())?;

let src_path = dst.path();
let dst_path = artifact_dir.join(&filename).into_path_unlocked();
std::fs::rename(src_path, dst_path)?;

result.push(dst);
}

Ok(result)
Expand Down
Loading