@@ -105,14 +105,42 @@ public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, s
105105 /// <param name="transformedPath">The transformed path to the input file.</param>
106106 /// <param name="inputEncoding">The encoding used by the input file.</param>
107107 public void Archive ( string originalPath , PathTransformer . ITransformedPath transformedPath , Encoding inputEncoding )
108+ {
109+ Archive ( ( ) =>
110+ {
111+ var fullInputPath = Path . GetFullPath ( originalPath ) ;
112+ return File . ReadAllText ( fullInputPath , inputEncoding ) ;
113+ } , transformedPath ) ;
114+ }
115+
116+ public void ArchiveContent ( string contents , PathTransformer . ITransformedPath transformedPath )
117+ {
118+ Archive ( ( ) => contents , transformedPath ) ;
119+ }
120+
121+ private void Archive ( Func < string > getContent , PathTransformer . ITransformedPath transformedPath )
108122 {
109123 if ( string . IsNullOrEmpty ( archive ) )
124+ {
110125 return ;
126+ }
111127
112- // Calling GetFullPath makes this use the canonical capitalisation, if the file exists.
113- var fullInputPath = Path . GetFullPath ( originalPath ) ;
128+ var dest = FileUtils . NestPaths ( logger , archive , transformedPath . Value ) ;
129+ try
130+ {
131+ var tmpSrcFile = Path . GetTempFileName ( ) ;
132+ File . WriteAllText ( tmpSrcFile , getContent ( ) , utf8 ) ;
114133
115- ArchivePath ( fullInputPath , transformedPath , inputEncoding ) ;
134+ FileUtils . MoveOrReplace ( tmpSrcFile , dest ) ;
135+ }
136+ catch ( Exception ex )
137+ {
138+ // If this happened, it was probably because
139+ // - the same file was compiled multiple times, or
140+ // - the file doesn't exist (due to wrong #line directive or because it's an in-memory source generated AST).
141+ // In any case, this is not a fatal error.
142+ logger . LogWarning ( "Problem archiving " + dest + ": " + ex ) ;
143+ }
116144 }
117145
118146 /// <summary>
@@ -185,37 +213,6 @@ public void Emit(ITrapEmitter emitter)
185213 emitter . EmitTrap ( Writer ) ;
186214 }
187215
188- /// <summary>
189- /// Attempts to archive the specified input file to the normal area of the source archive.
190- /// The file's path must be sufficiently short so as to render the path of its copy in the
191- /// source archive less than the system path limit of 260 characters.
192- /// </summary>
193- /// <param name="fullInputPath">The full path to the input file.</param>
194- /// <param name="transformedPath">The transformed path to the input file.</param>
195- /// <param name="inputEncoding">The encoding used by the input file.</param>
196- /// <exception cref="PathTooLongException">If the output path in the source archive would
197- /// exceed the system path limit of 260 characters.</exception>
198- private void ArchivePath ( string fullInputPath , PathTransformer . ITransformedPath transformedPath , Encoding inputEncoding )
199- {
200- var dest = FileUtils . NestPaths ( logger , archive , transformedPath . Value ) ;
201- try
202- {
203- var contents = File . ReadAllText ( fullInputPath , inputEncoding ) ;
204- var tmpSrcFile = Path . GetTempFileName ( ) ;
205- File . WriteAllText ( tmpSrcFile , contents , utf8 ) ;
206-
207- FileUtils . MoveOrReplace ( tmpSrcFile , dest ) ;
208- }
209- catch ( Exception ex )
210- {
211- // If this happened, it was probably because
212- // - the same file was compiled multiple times, or
213- // - the file doesn't exist (due to wrong #line directive or because it's an in-memory source generated AST).
214- // In any case, this is not a fatal error.
215- logger . LogWarning ( "Problem archiving " + dest + ": " + ex ) ;
216- }
217- }
218-
219216 private static string TrapExtension ( CompressionMode compression )
220217 {
221218 switch ( compression )
0 commit comments