@@ -3299,7 +3299,7 @@ func getGitignorePatterns(directoryPath, zipFilePath string) ([]string, error) {
32993299 for _ , line := range lines {
33003300 line = strings .TrimSpace (line )
33013301
3302- //This condition skips lines that are empty, comments.
3302+ // This condition skips lines that are empty, comments.
33033303 // Excluding the lines that contain negotiation characters like !, which are used to negate patterns
33043304 if line == "" || strings .HasPrefix (line , "#" ) || strings .HasPrefix (line , "!" ) {
33053305 continue
@@ -3343,20 +3343,28 @@ func readGitIgnoreFromZip(zipPath string) ([]byte, error) {
33433343 expectedGitignorePath := rootFolder + "/.gitignore"
33443344
33453345 for _ , f := range r .File {
3346- if f .Name == expectedGitignorePath {
3347- rc , err := f .Open ()
3348- if err != nil {
3349- return []byte ("" ), fmt .Errorf ("failed to open .gitignore inside zip: %w" , err )
3350- }
3351- defer rc .Close ()
3346+ if f .Name != expectedGitignorePath {
3347+ continue
3348+ }
3349+ rc , err := f .Open ()
3350+ if err != nil {
3351+ return []byte ("" ), fmt .Errorf ("failed to open .gitignore inside zip: %w" , err )
3352+ }
33523353
3353- // Read file content
3354- data , err := io .ReadAll (rc )
3354+ // Read file content
3355+ data , err := io .ReadAll (rc )
3356+ if err != nil {
3357+ err := rc .Close ()
33553358 if err != nil {
3356- return [] byte ( "" ), fmt . Errorf ( "failed to read .gitignore content inside zip : %w" , err )
3359+ return nil , err
33573360 }
3358- return data , nil
3361+ return []byte ("" ), fmt .Errorf ("failed to read .gitignore content inside zip : %w" , err )
3362+ }
3363+ // Close with error handling
3364+ if err := rc .Close (); err != nil {
3365+ logger .PrintfIfVerbose ("Error closing .gitignore reader: %v" , err )
33593366 }
3367+ return data , nil
33603368 }
33613369 return []byte ("" ), fmt .Errorf (".gitignore not found in zip: %s" , zipPath )
33623370}
0 commit comments