@@ -23,6 +23,13 @@ const sourceCodeFolderName = 'sourceCode'
2323const packagesFolderName = 'packages'
2424const thirdPartyPackageFolderName = 'thirdpartypackages'
2525const customTransformationFolderName = 'customTransformation'
26+ const filteredExtensions = [ '.suo' , '.meta' , '.user' , '.obj' , '.tmp' , '.log' , '.dbmdl' , '.jfm' , '.pdb' ]
27+ const filteredDirectories = [ '.git' , 'bin' , 'obj' , '.idea' , '.vs' , 'artifactworkspace' , 'node_modules' , 'nuget.config' ]
28+ const failedCopies : string [ ] = [ ]
29+ const filteredPathRegex : RegExp [ ] = [
30+ / \\ u s e r s \\ [ ^ \\ ] + \\ a p p d a t a / i, // IgnoreCase flag with 'i'
31+ / .+ \. ( v s p s c c | v s s s c c ) $ / ,
32+ ]
2633
2734export class ArtifactManager {
2835 private workspace : Workspace
@@ -160,16 +167,25 @@ export class ArtifactManager {
160167
161168 async createRequirementJsonContent ( request : StartTransformRequest ) : Promise < RequirementJson > {
162169 const projects : Project [ ] = [ ]
163-
164170 for ( const project of request . ProjectMetadata ) {
165171 const sourceCodeFilePaths = project . SourceCodeFilePaths . filter ( filePath => filePath )
166172 const codeFiles : CodeFile [ ] = [ ]
167173 const references : References [ ] = [ ]
168-
169174 for ( const filePath of sourceCodeFilePaths ) {
170175 try {
176+ if ( this . shouldFilterFile ( filePath ) ) {
177+ continue
178+ }
171179 await this . copySourceFile ( request . SolutionRootPath , filePath )
172180 const contentHash = await this . calculateMD5Async ( filePath )
181+ if ( contentHash . length == 0 ) {
182+ //if can't generate hash then file copy failed previously
183+ continue
184+ }
185+ if ( contentHash . length == 0 ) {
186+ //if can't generate hash then file copy failed previously
187+ continue
188+ }
173189 const relativePath = this . normalizeSourceFileRelativePath ( request . SolutionRootPath , filePath )
174190 codeFiles . push ( {
175191 contentMd5Hash : contentHash ,
@@ -181,6 +197,9 @@ export class ArtifactManager {
181197 }
182198
183199 for ( const reference of project . ExternalReferences ) {
200+ if ( this . shouldFilterFile ( reference . AssemblyFullPath ) ) {
201+ continue
202+ }
184203 try {
185204 const relativePath = this . normalizeReferenceFileRelativePath (
186205 reference . RelativePath ,
@@ -215,6 +234,8 @@ export class ArtifactManager {
215234 for ( const pkg of request . PackageReferences ) {
216235 if ( ! pkg . NetCompatiblePackageFilePath ) {
217236 continue
237+ } else if ( this . shouldFilterFile ( pkg . NetCompatiblePackageFilePath ) ) {
238+ continue
218239 }
219240 try {
220241 const packageRelativePath = this . normalizePackageFileRelativePath ( pkg . NetCompatiblePackageFilePath )
@@ -301,7 +322,24 @@ export class ArtifactManager {
301322 `Custom transformation folder not accessible (not found or no permissions): ${ customTransformationPath } `
302323 )
303324 }
304-
325+ this . logging . log (
326+ `Files with extensions ${ filteredExtensions . join ( ', ' ) } are not zipped, as they are not necessary for transformation`
327+ )
328+ this . logging . log (
329+ `Files in directories ${ filteredDirectories . join ( ', ' ) } are not zipped, as they are not necessary for transformation`
330+ )
331+ if ( failedCopies . length > 0 ) {
332+ this . logging . log ( `Files - ${ failedCopies . join ( ',' ) } - could not be copied.` )
333+ }
334+ this . logging . log (
335+ `Files with extensions ${ filteredExtensions . join ( ', ' ) } are not zipped, as they are not necessary for transformation`
336+ )
337+ this . logging . log (
338+ `Files in directories ${ filteredDirectories . join ( ', ' ) } are not zipped, as they are not necessary for transformation`
339+ )
340+ if ( failedCopies . length > 0 ) {
341+ this . logging . log ( `Files - ${ failedCopies . join ( ',' ) } - could not be copied.` )
342+ }
305343 const zipPath = path . join ( this . workspacePath , zipFileName )
306344 this . logging . log ( 'Zipping files to ' + zipPath )
307345 await this . zipDirectory ( folderPath , zipPath )
@@ -394,17 +432,23 @@ export class ArtifactManager {
394432 //Packages folder has been deleted to avoid duplicates in artifacts.zip
395433 return
396434 }
397-
398- return new Promise < void > ( ( resolve , reject ) => {
399- fs . copyFile ( sourceFilePath , destFilePath , err => {
400- if ( err ) {
401- this . logging . log ( `Failed to copy from ${ sourceFilePath } and error is ${ err } ` )
402- reject ( err )
403- } else {
404- resolve ( )
405- }
435+ if ( this . shouldFilterFile ( sourceFilePath ) ) {
436+ return
437+ } else {
438+ return new Promise < void > ( ( resolve , reject ) => {
439+ fs . copyFile ( sourceFilePath , destFilePath , err => {
440+ if ( err ) {
441+ this . logging . log ( `Failed to copy from ${ sourceFilePath } and error is ${ err } ` )
442+ failedCopies . push ( sourceFilePath )
443+ resolve ( )
444+ failedCopies . push ( sourceFilePath )
445+ resolve ( )
446+ } else {
447+ resolve ( )
448+ }
449+ } )
406450 } )
407- } )
451+ }
408452 }
409453
410454 async calculateMD5Async ( filePath : string ) : Promise < string > {
@@ -420,4 +464,17 @@ export class ArtifactManager {
420464 return ''
421465 }
422466 }
467+ shouldFilterFile ( filePath : string ) : boolean {
468+ if ( filteredExtensions . includes ( path . extname ( filePath ) . toLowerCase ( ) ) ) {
469+ return true
470+ }
471+ const dirPath = path . dirname ( filePath ) . toLowerCase ( )
472+ const pathSegments = dirPath . split ( path . sep )
473+
474+ if ( pathSegments . some ( segment => filteredDirectories . includes ( segment ) ) ) {
475+ return true
476+ }
477+
478+ return filteredPathRegex . some ( regex => regex . test ( filePath ) )
479+ }
423480}
0 commit comments