@@ -22,7 +22,6 @@ internal static partial class MimeTypeSyncTool
2222
2323 private static readonly string [ ] DefaultSupplementalSources =
2424 [
25- "https://raw.githubusercontent.com/jshttp/mime-db/master/db.json" ,
2625 "https://raw.githubusercontent.com/apache/httpd/trunk/docs/conf/mime.types"
2726 ] ;
2827
@@ -58,9 +57,9 @@ public static async Task<int> RunAsync(string[] args)
5857 sourceMappings . AddRange ( ParseSupplementalSource ( source , raw , kind ) ) ;
5958 }
6059
61- sourceMappings . AddRange ( CustomMappings ( ) . Select ( static kvp => new SourceMapping ( kvp . Key , kvp . Value , MimeSourceKind . Curated ) ) ) ;
62-
63- var existing = LoadExisting ( options . OutputPath ) ;
60+ var existing = options . PreserveExisting
61+ ? LoadExisting ( options . OutputPath )
62+ : new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
6463 var merged = MergeMappings ( sourceMappings , existing , options . PreferRemote ) ;
6564 var mergedMetadata = BuildMergedMetadata ( metadata , merged ) ;
6665
@@ -502,24 +501,6 @@ private static IReadOnlyDictionary<string, MimeMetadata> BuildMergedMetadata(Dic
502501 . ToDictionary ( static kvp => kvp . Key , static kvp => kvp . Value . NormalizeForOutput ( ) , StringComparer . OrdinalIgnoreCase ) ;
503502 }
504503
505- private static IEnumerable < KeyValuePair < string , string > > CustomMappings ( )
506- {
507- yield return new KeyValuePair < string , string > ( "tar.gz" , "application/gzip" ) ;
508- yield return new KeyValuePair < string , string > ( "gz" , "application/gzip" ) ;
509- yield return new KeyValuePair < string , string > ( "tar.bz2" , "application/x-bzip2" ) ;
510- yield return new KeyValuePair < string , string > ( "tar.xz" , "application/x-xz" ) ;
511- yield return new KeyValuePair < string , string > ( "tar.zst" , "application/zstd" ) ;
512- yield return new KeyValuePair < string , string > ( "d.ts" , "application/typescript" ) ;
513- yield return new KeyValuePair < string , string > ( "cjs" , "application/node" ) ;
514- yield return new KeyValuePair < string , string > ( "mjs" , "text/javascript" ) ;
515- yield return new KeyValuePair < string , string > ( "wasm" , "application/wasm" ) ;
516- yield return new KeyValuePair < string , string > ( "heic" , "image/heic" ) ;
517- yield return new KeyValuePair < string , string > ( "heif" , "image/heif" ) ;
518- yield return new KeyValuePair < string , string > ( "ics" , "text/calendar" ) ;
519- yield return new KeyValuePair < string , string > ( "ps1" , "application/x-powershell" ) ;
520- yield return new KeyValuePair < string , string > ( "appx" , "application/vnd.ms-appx" ) ;
521- }
522-
523504 private static void WriteMimeMap ( string outputPath , IReadOnlyDictionary < string , MergedMapping > data )
524505 {
525506 Directory . CreateDirectory ( Path . GetDirectoryName ( outputPath ) ! ) ;
@@ -844,19 +825,13 @@ private static string FormatXref(XElement xref)
844825
845826 private static MimeSourceKind ClassifySupplementalSource ( string source )
846827 {
847- if ( source . Contains ( "jshttp/mime-db" , StringComparison . OrdinalIgnoreCase ) ||
848- source . EndsWith ( "db.json" , StringComparison . OrdinalIgnoreCase ) )
849- {
850- return MimeSourceKind . MimeDb ;
851- }
852-
853828 if ( source . Contains ( "apache" , StringComparison . OrdinalIgnoreCase ) ||
854829 source . EndsWith ( "mime.types" , StringComparison . OrdinalIgnoreCase ) )
855830 {
856831 return MimeSourceKind . Apache ;
857832 }
858833
859- return MimeSourceKind . MimeDb ;
834+ return MimeSourceKind . Custom ;
860835 }
861836
862837 [ GeneratedRegex ( @"^\s*(?<name>[A-Za-z][A-Za-z0-9 /&().+\-]*(?:\(s\))?)\s*:\s*(?<value>.*)$" , RegexOptions . Compiled ) ]
@@ -897,6 +872,7 @@ internal sealed record SyncOptions(
897872 bool PreferRemote ,
898873 bool UseIana ,
899874 bool SkipIanaTemplates ,
875+ bool PreserveExisting ,
900876 int TemplateConcurrency )
901877 {
902878 public static SyncOptions Parse ( string [ ] args )
@@ -908,6 +884,7 @@ public static SyncOptions Parse(string[] args)
908884 bool preferRemote = false ;
909885 bool useIana = true ;
910886 bool skipIanaTemplates = false ;
887+ bool preserveExisting = false ;
911888 var templateConcurrency = 8 ;
912889 var customSupplementalSources = false ;
913890
@@ -952,13 +929,16 @@ public static SyncOptions Parse(string[] args)
952929 case "--prefer-remote" :
953930 preferRemote = true ;
954931 break ;
932+ case "--preserve-existing" :
933+ preserveExisting = true ;
934+ break ;
955935 }
956936 }
957937
958938 output ??= Path . GetFullPath ( Path . Combine ( AppContext . BaseDirectory , ".." , ".." , ".." , ".." , "ManagedCode.MimeTypes" , "mimeTypes.json" ) ) ;
959939 metadataOutput ??= Path . Combine ( Path . GetDirectoryName ( output ) ! , "mimeTypes.metadata.json" ) ;
960940
961- return new SyncOptions ( ianaSource , supplementalSources , output , metadataOutput , preferRemote , useIana , skipIanaTemplates , templateConcurrency ) ;
941+ return new SyncOptions ( ianaSource , supplementalSources , output , metadataOutput , preferRemote , useIana , skipIanaTemplates , preserveExisting , templateConcurrency ) ;
962942 }
963943
964944 private static void AddSources ( List < string > sources , string value )
@@ -975,10 +955,9 @@ internal enum MimeSourceKind
975955{
976956 Existing ,
977957 Apache ,
978- MimeDb ,
958+ Custom ,
979959 Iana ,
980- ExistingPreferred ,
981- Curated
960+ ExistingPreferred
982961}
983962
984963internal static class MimeSourceKindExtensions
@@ -990,9 +969,8 @@ public static int Priority(this MimeSourceKind kind)
990969 MimeSourceKind . Existing => 0 ,
991970 MimeSourceKind . Apache => 10 ,
992971 MimeSourceKind . Iana => 15 ,
993- MimeSourceKind . MimeDb => 20 ,
972+ MimeSourceKind . Custom => 20 ,
994973 MimeSourceKind . ExistingPreferred => 35 ,
995- MimeSourceKind . Curated => 40 ,
996974 _ => 0
997975 } ;
998976 }
@@ -1002,9 +980,8 @@ public static string SourceName(this MimeSourceKind kind)
1002980 return kind switch
1003981 {
1004982 MimeSourceKind . Apache => "apache" ,
1005- MimeSourceKind . MimeDb => "mime-db " ,
983+ MimeSourceKind . Custom => "custom " ,
1006984 MimeSourceKind . Iana => "iana" ,
1007- MimeSourceKind . Curated => "curated" ,
1008985 MimeSourceKind . ExistingPreferred => "existing" ,
1009986 _ => "existing"
1010987 } ;
0 commit comments