Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to publish: failed to prepare local package for uploading #11522

Closed
contactomorph opened this issue Dec 29, 2022 · 5 comments · Fixed by #12036
Closed

Impossible to publish: failed to prepare local package for uploading #11522

contactomorph opened this issue Dec 29, 2022 · 5 comments · Fixed by #12036
Assignees
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug Command-package E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@contactomorph
Copy link

contactomorph commented Dec 29, 2022

Problem

When trying to publish my crate:

PS C:\repos\tensorism> cargo publish -vv
    Updating crates.io index
   Packaging tensorism v0.1.0 (C:\repos\tensorism)
   Archiving
error: failed to prepare local package for uploading

Caused by:
  failed to open for archiving: `C:\repos\tensorism`

Caused by:
  Access is denied. (os error 5)

Notes

I tried to publish it from a friend's machine, suspecting the problem was related to something about my local environment but I got exactly the same error.

Version

cargo 1.67.0-nightly (f6e737b1e 2022-12-02)
release: 1.67.0-nightly
commit-hash: f6e737b1e3386adb89333bf06a01f68a91ac5306
commit-date: 2022-12-02
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Pro) [64-bit]
@contactomorph contactomorph added the C-bug Category: bug label Dec 29, 2022
@weihanglo weihanglo added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label Feb 19, 2023
@weihanglo
Copy link
Member

Not exactly the same issue but probably you can follow this to investigate #11544.

@ehuss
Copy link
Contributor

ehuss commented Apr 25, 2023

This is caused by having an empty readme field in Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
readme = ""

This also happens with license-file = "".

I think the solution is to generate a better error message when readme or license-file is set to an empty string.

@ehuss ehuss added E-easy Experience: Easy A-diagnostics Area: Error and warning messages generated by Cargo itself. S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review Command-package and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Apr 25, 2023
@kylematsuda
Copy link
Contributor

@rustbot claim

@kylematsuda
Copy link
Contributor

Hi! So the problem seems to be the following lines from the build_ar_list function for license-file (and a similar section below that for readme):

if let Some(license_file) = &pkg.manifest().metadata().license_file {
let license_path = Path::new(license_file);
let abs_file_path = paths::normalize_path(&pkg.root().join(license_path));
if abs_file_path.exists() {
check_for_file_and_add(
"license-file",
license_path,
abs_file_path,
pkg,
&mut result,
ws,
)?;
} else {

If license-file = "", then abs_file_path points at the crate root and the abs_file_path.exists() check is true, leading to abs_file_path being added to the archive list. The error then occurs later when tar is eventually called, which expects a file for license-file instead of a directory.

A simple fix could be to change Path::exists to Path::is_file. This would also catch the case where an existing directory is provided for license-file, for example license-file = "./src" (which currently causes the same error as license-file = "").

Does that approach sound okay? The same change (+ adding a helpful warning message) should also work for readme.

@ehuss
Copy link
Contributor

ehuss commented Apr 25, 2023

That sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug Command-package E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants