use tar::{Archive, Builder, EntryType, Header};
use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor};
-use crate::core::{Feature, Verbosity, Workspace};
+use crate::core::{Feature, Shell, Verbosity, Workspace};
use crate::core::{Package, PackageId, PackageSet, Resolve, Source, SourceId};
use crate::ops;
use crate::sources::PathSource;
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::paths;
use crate::util::toml::TomlManifest;
-use crate::util::{self, Config, FileLock};
+use crate::util::{self, restricted_names, Config, FileLock};
pub struct PackageOpts<'cfg> {
pub config: &'cfg Config,
let root = pkg.root();
for src_file in src_files {
let rel_path = src_file.strip_prefix(&root)?.to_path_buf();
- check_filename(&rel_path)?;
+ check_filename(&rel_path, &mut ws.config().shell())?;
let rel_str = rel_path
.to_str()
.ok_or_else(|| {
//
// To help out in situations like this, issue about weird filenames when
// packaging as a "heads up" that something may not work on other platforms.
-fn check_filename(file: &Path) -> CargoResult<()> {
+fn check_filename(file: &Path, shell: &mut Shell) -> CargoResult<()> {
let name = match file.file_name() {
Some(name) => name,
None => return Ok(()),
file.display()
)
}
+ let mut check_windows = |name| -> CargoResult<()> {
+ if restricted_names::is_windows_reserved(name) {
+ shell.warn(format!(
+ "file {} is a reserved Windows filename, \
+ it will not work on Windows platforms",
+ file.display()
+ ))?;
+ }
+ Ok(())
+ };
+ for component in file.iter() {
+ if let Some(component) = component.to_str() {
+ check_windows(component)?;
+ }
+ }
+ if file.extension().is_some() {
+ if let Some(stem) = file.file_stem().and_then(|s| s.to_str()) {
+ check_windows(stem)?;
+ }
+ }
Ok(())
}
let orig = read_to_string(p.root().join("target/package/foo-1.0.0/Cargo.toml.orig")).unwrap();
assert!(orig.contains("license-file = \"../LICENSE\""));
}
+
+#[cargo_test]
+#[cfg(not(windows))] // Don't want to create invalid files on Windows.
+fn package_restricted_windows() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ license = "MIT"
+ description = "foo"
+ homepage = "foo"
+ "#,
+ )
+ .file("src/lib.rs", "pub mod con;\npub mod aux;")
+ .file("src/con.rs", "pub fn f() {}")
+ .file("src/aux/mod.rs", "pub fn f() {}")
+ .build();
+
+ p.cargo("package")
+ .with_stderr(
+ "\
+[WARNING] file src/aux/mod.rs is a reserved Windows filename, it will not work on Windows platforms
+[WARNING] file src/con.rs is a reserved Windows filename, it will not work on Windows platforms
+[PACKAGING] foo [..]
+[VERIFYING] foo [..]
+[COMPILING] foo [..]
+[FINISHED] [..]
+",
+ )
+ .run();
+}