@@ -13,14 +13,14 @@ use log::debug;
1313use tar:: { Archive , Builder , EntryType , Header } ;
1414
1515use crate :: core:: compiler:: { BuildConfig , CompileMode , DefaultExecutor , Executor } ;
16- use crate :: core:: { Feature , Verbosity , Workspace } ;
16+ use crate :: core:: { Feature , Shell , Verbosity , Workspace } ;
1717use crate :: core:: { Package , PackageId , PackageSet , Resolve , Source , SourceId } ;
1818use crate :: ops;
1919use crate :: sources:: PathSource ;
2020use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
2121use crate :: util:: paths;
2222use crate :: util:: toml:: TomlManifest ;
23- use crate :: util:: { self , Config , FileLock } ;
23+ use crate :: util:: { self , restricted_names , Config , FileLock } ;
2424
2525pub struct PackageOpts < ' cfg > {
2626 pub config : & ' cfg Config ,
@@ -142,7 +142,7 @@ fn build_ar_list(
142142 let root = pkg. root ( ) ;
143143 for src_file in src_files {
144144 let rel_path = src_file. strip_prefix ( & root) ?. to_path_buf ( ) ;
145- check_filename ( & rel_path) ?;
145+ check_filename ( & rel_path, & mut ws . config ( ) . shell ( ) ) ?;
146146 let rel_str = rel_path
147147 . to_str ( )
148148 . ok_or_else ( || {
@@ -804,7 +804,7 @@ fn report_hash_difference(orig: &HashMap<PathBuf, u64>, after: &HashMap<PathBuf,
804804//
805805// To help out in situations like this, issue about weird filenames when
806806// packaging as a "heads up" that something may not work on other platforms.
807- fn check_filename ( file : & Path ) -> CargoResult < ( ) > {
807+ fn check_filename ( file : & Path , shell : & mut Shell ) -> CargoResult < ( ) > {
808808 let name = match file. file_name ( ) {
809809 Some ( name) => name,
810810 None => return Ok ( ( ) ) ,
@@ -825,5 +825,25 @@ fn check_filename(file: &Path) -> CargoResult<()> {
825825 file. display( )
826826 )
827827 }
828+ let mut check_windows = |name| -> CargoResult < ( ) > {
829+ if restricted_names:: is_windows_reserved ( name) {
830+ shell. warn ( format ! (
831+ "file {} is a reserved Windows filename, \
832+ it will not work on Windows platforms",
833+ file. display( )
834+ ) ) ?;
835+ }
836+ Ok ( ( ) )
837+ } ;
838+ for component in file. iter ( ) {
839+ if let Some ( component) = component. to_str ( ) {
840+ check_windows ( component) ?;
841+ }
842+ }
843+ if file. extension ( ) . is_some ( ) {
844+ if let Some ( stem) = file. file_stem ( ) . and_then ( |s| s. to_str ( ) ) {
845+ check_windows ( stem) ?;
846+ }
847+ }
828848 Ok ( ( ) )
829849}
0 commit comments