Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax requirement for valid rows in stops.txt for fetch and import #356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dmfr/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func MainImportFeedVersion(adapter tldb.Adapter, opts Options) (Result, error) {
if err != nil {
return err
}
required := []string{"agency.txt", "routes.txt", "stops.txt"}
required := []string{"agency.txt", "routes.txt"}
for _, fn := range required {
if c := fviresult.EntityCount[fn]; c == 0 {
return fmt.Errorf("failed to import any entities from required file '%s'", fn)
Expand Down
18 changes: 9 additions & 9 deletions tlcsv/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (reader *Reader) ValidateStructure() []error {
}
// Check if these files contain valid headers
// TODO: An error in the header should also stop a file from being opened for further CSV reading.
check := func(ent tl.Entity) []error {
check := func(ent tl.Entity, rowsRequired bool) []error {
fileerrs := []error{}
efn := ent.Filename()
err := reader.Adapter.OpenFile(efn, func(in io.Reader) {
Expand All @@ -85,7 +85,7 @@ func (reader *Reader) ValidateStructure() []error {
fileerrs = append(fileerrs, causes.NewFileUnreadableError(efn, readerr))
return
}
if rowcount == 0 {
if rowcount == 0 && rowsRequired {
fileerrs = append(fileerrs, causes.NewFileRequiredError(efn))
return
}
Expand Down Expand Up @@ -125,15 +125,15 @@ func (reader *Reader) ValidateStructure() []error {
}
return fileerrs
}
allerrs = append(allerrs, check(&tl.Stop{})...)
allerrs = append(allerrs, check(&tl.Route{})...)
allerrs = append(allerrs, check(&tl.Agency{})...)
allerrs = append(allerrs, check(&tl.Trip{})...)
allerrs = append(allerrs, check(&tl.StopTime{})...)
allerrs = append(allerrs, check(&tl.Stop{}, false)...)
allerrs = append(allerrs, check(&tl.Route{}, true)...)
allerrs = append(allerrs, check(&tl.Agency{}, true)...)
allerrs = append(allerrs, check(&tl.Trip{}, true)...)
allerrs = append(allerrs, check(&tl.StopTime{}, true)...)
cal := tl.Calendar{}
cd := tl.CalendarDate{}
calerrs := check(&cal)
cderrs := check(&cd)
calerrs := check(&cal, true)
cderrs := check(&cd, true)
if reader.ContainsFile(cal.Filename()) && reader.ContainsFile(cd.Filename()) {
if len(calerrs) > 0 && len(cderrs) > 0 {
allerrs = append(allerrs, calerrs...)
Expand Down
Loading