Skip to content

Commit

Permalink
refactor(Updated to extract the file name from path):
Browse files Browse the repository at this point in the history
  • Loading branch information
br648 committed Aug 19, 2024
1 parent 5f0c806 commit 5dd609b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/conveyal/gtfs/loader/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -782,7 +783,7 @@ public CsvReader getCsvReader(ZipFile zipFile, SQLErrorStorage sqlErrorStorage)
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry e = entries.nextElement();
if (e.getName().endsWith(tableFileName)) {
if (Paths.get(e.getName()).getFileName().toString().equals(tableFileName)) {
entry = e;
if (sqlErrorStorage != null) sqlErrorStorage.storeError(NewGTFSError.forTable(this, TABLE_IN_SUBDIRECTORY));
break;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/conveyal/gtfs/model/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand Down Expand Up @@ -282,15 +283,16 @@ protected <K, V> V getRefField(String column, boolean required, Map<K, V> target
* @param zip the zip file from which to read a table
*/
public void loadTable(ZipFile zip) throws IOException {
ZipEntry entry = zip.getEntry(tableName + ".txt");
String fileName = tableName + ".txt";
ZipEntry entry = zip.getEntry(fileName);
if (entry == null) {
Enumeration<? extends ZipEntry> entries = zip.entries();
// check if table is contained within sub-directory
while (entries.hasMoreElements()) {
ZipEntry e = entries.nextElement();
if (e.getName().equals(tableName + ".txt")) {
if (Paths.get(e.getName()).getFileName().toString().equals(fileName)) {
entry = e;
feed.errors.add(new TableInSubdirectoryError(tableName, entry.getName().replace(tableName + ".txt", "")));
feed.errors.add(new TableInSubdirectoryError(tableName, entry.getName().replace(fileName, "")));
}
}
/* This GTFS table did not exist in the zip. */
Expand Down

0 comments on commit 5dd609b

Please sign in to comment.