Skip to content

Commit

Permalink
Merge pull request #4 from signaux-faibles/fix/close-on-error
Browse files Browse the repository at this point in the history
fix close channel in case on zip open error
  • Loading branch information
chrnin authored Aug 17, 2023
2 parents 3c5b146 + 30a9f96 commit 19d1a10
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions sireneUL.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

var SireneULHeaders = strings.Split("siren statutDiffusionUniteLegale unitePurgeeUniteLegale dateCreationUniteLegale sigleUniteLegale sexeUniteLegale prenom1UniteLegale prenom2UniteLegale prenom3UniteLegale prenom4UniteLegale prenomUsuelUniteLegale pseudonymeUniteLegale identifiantAssociationUniteLegale trancheEffectifsUniteLegale anneeEffectifsUniteLegale dateDernierTraitementUniteLegale nombrePeriodesUniteLegale categorieEntreprise anneeCategorieEntreprise dateDebut etatAdministratifUniteLegale nomUniteLegale nomUsageUniteLegale denominationUniteLegale denominationUsuelle1UniteLegale denominationUsuelle2UniteLegale denominationUsuelle3UniteLegale categorieJuridiqueUniteLegale activitePrincipaleUniteLegale nomenclatureActivitePrincipaleUniteLegale nicSiegeUniteLegale economieSocialeSolidaireUniteLegale caractereEmployeurUniteLegale", " ")
var SireneULMap = mapHeaders(SireneULHeaders)

// GeoSireneParses returns a GeoSirene channel.
// Errors are transmitted trough GeoSirene.Error() function.
Expand All @@ -37,6 +36,8 @@ func sireneULFromCsv(row []string) SireneUL {

func parseSireneUL(ctx context.Context, file io.ReadCloser, s chan SireneUL) {
c := csv.NewReader(file)
defer file.Close()

if head, err := c.Read(); checkHeader(SireneULHeaders, head) && err != nil {
s <- SireneUL{err: err}
return
Expand All @@ -45,13 +46,11 @@ func parseSireneUL(ctx context.Context, file io.ReadCloser, s chan SireneUL) {
row, err := c.Read()
if err != nil {
if err == io.EOF {
err := file.Close()
if err != nil {
s <- SireneUL{err: err}
}
return
}
file.Close()
s <- SireneUL{err: err}
return
}
Expand All @@ -64,7 +63,6 @@ func parseSireneUL(ctx context.Context, file io.ReadCloser, s chan SireneUL) {
case <-ctx.Done():
return
case s <- sirene:
continue
}
}
}
Expand All @@ -80,13 +78,12 @@ func readPlainSireneUL(ctx context.Context, path string, s chan SireneUL) {
}

func readZipSireneUL(ctx context.Context, path string, s chan SireneUL) {
defer close(s)
zr, err := zip.OpenReader(path)
if err != nil {
s <- SireneUL{err: err}
return
}

defer close(s)
defer zr.Close()

for _, zf := range zr.File {
Expand Down

0 comments on commit 19d1a10

Please sign in to comment.