@@ -3292,7 +3292,7 @@ func getGitignorePatterns(directoryPath, zipFilePath string) ([]string, error) {
32923292 for _ , line := range lines {
32933293 line = strings .TrimSpace (line )
32943294
3295- //This condition skips lines that are empty, comments.
3295+ // This condition skips lines that are empty, comments.
32963296 // Excluding the lines that contain negotiation characters like !, which are used to negate patterns
32973297 if line == "" || strings .HasPrefix (line , "#" ) || strings .HasPrefix (line , "!" ) {
32983298 continue
@@ -3336,20 +3336,28 @@ func readGitIgnoreFromZip(zipPath string) ([]byte, error) {
33363336 expectedGitignorePath := rootFolder + "/.gitignore"
33373337
33383338 for _ , f := range r .File {
3339- if f .Name == expectedGitignorePath {
3340- rc , err := f .Open ()
3341- if err != nil {
3342- return []byte ("" ), fmt .Errorf ("failed to open .gitignore inside zip: %w" , err )
3343- }
3344- defer rc .Close ()
3339+ if f .Name != expectedGitignorePath {
3340+ continue
3341+ }
3342+ rc , err := f .Open ()
3343+ if err != nil {
3344+ return []byte ("" ), fmt .Errorf ("failed to open .gitignore inside zip: %w" , err )
3345+ }
33453346
3346- // Read file content
3347- data , err := io .ReadAll (rc )
3347+ // Read file content
3348+ data , err := io .ReadAll (rc )
3349+ if err != nil {
3350+ err := rc .Close ()
33483351 if err != nil {
3349- return [] byte ( "" ), fmt . Errorf ( "failed to read .gitignore content inside zip : %w" , err )
3352+ return nil , err
33503353 }
3351- return data , nil
3354+ return []byte ("" ), fmt .Errorf ("failed to read .gitignore content inside zip : %w" , err )
3355+ }
3356+ // Close with error handling
3357+ if err := rc .Close (); err != nil {
3358+ logger .PrintfIfVerbose ("Error closing .gitignore reader: %v" , err )
33523359 }
3360+ return data , nil
33533361 }
33543362 return []byte ("" ), fmt .Errorf (".gitignore not found in zip: %s" , zipPath )
33553363}
0 commit comments