Skip to content

cargo package doesn't properly handle unreadable directories in the root #16465

@konstin

Description

@konstin

Problem

Cargo trips over an unreadable directory in the root instead of ignoring is like other irrelevant directories. This causes both cargo and downstream tools such as maturin to fail in an otherwise buildable project (PyO3/maturin#2777).

Steps

Create a project with an unreadable directory - Say one created by a docker container running as root. foo is the unreadable directory, bar is the readable control:

mkdir proj
cd proj
cargo init --vcs none --lib
mkdir foo
chmod 000 foo
mkdir bar

Unlike other directories, foo is included in the file list:

$ cargo package --list
warning: manifest has no description, license, license-file, documentation, homepage or repository
  |
  = note: see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
Cargo.lock
Cargo.toml
Cargo.toml.orig
foo
src/lib.rs

This subsequently fails builds, both for cargo and downstream for maturin:

$ cargo package
warning: manifest has no description, license, license-file, documentation, homepage or repository
  |
  = note: see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
   Packaging proj v0.1.0 (/home/konsti/projects/proj)
error: failed to prepare local package for uploading

Caused by:
  failed to open for archiving: `/home/konsti/projects/proj/foo`

Caused by:
  Permission denied (os error 13)

There's a separate issue where cargo's cargo package git integration fails with such a directory, while the git CLI only warns, but that's a separate problem.

Possible Solution(s)

No response

Notes

No response

Version

$ cargo --version
cargo 1.92.0 (344c4567c 2025-10-21)
$ cargo +nightly --version
cargo 1.94.0-nightly (b54051b15 2025-12-30)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions