@@ -13,14 +13,14 @@ use log::debug;
13
13
use tar:: { Archive , Builder , EntryType , Header } ;
14
14
15
15
use crate :: core:: compiler:: { BuildConfig , CompileMode , DefaultExecutor , Executor } ;
16
- use crate :: core:: { Feature , Verbosity , Workspace } ;
16
+ use crate :: core:: { Feature , Shell , Verbosity , Workspace } ;
17
17
use crate :: core:: { Package , PackageId , PackageSet , Resolve , Source , SourceId } ;
18
18
use crate :: ops;
19
19
use crate :: sources:: PathSource ;
20
20
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
21
21
use crate :: util:: paths;
22
22
use crate :: util:: toml:: TomlManifest ;
23
- use crate :: util:: { self , Config , FileLock } ;
23
+ use crate :: util:: { self , restricted_names , Config , FileLock } ;
24
24
25
25
pub struct PackageOpts < ' cfg > {
26
26
pub config : & ' cfg Config ,
@@ -142,7 +142,7 @@ fn build_ar_list(
142
142
let root = pkg. root ( ) ;
143
143
for src_file in src_files {
144
144
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 ( ) ) ?;
146
146
let rel_str = rel_path
147
147
. to_str ( )
148
148
. ok_or_else ( || {
@@ -804,7 +804,7 @@ fn report_hash_difference(orig: &HashMap<PathBuf, u64>, after: &HashMap<PathBuf,
804
804
//
805
805
// To help out in situations like this, issue about weird filenames when
806
806
// 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 < ( ) > {
808
808
let name = match file. file_name ( ) {
809
809
Some ( name) => name,
810
810
None => return Ok ( ( ) ) ,
@@ -825,5 +825,25 @@ fn check_filename(file: &Path) -> CargoResult<()> {
825
825
file. display( )
826
826
)
827
827
}
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
+ }
828
848
Ok ( ( ) )
829
849
}
0 commit comments