fix: EgovIndexFileWriter 가 초기 파일명 생성 시 지정한 확장자를 .csv 로 대체하는 문제 수정 - #363
Open
wantaekchoi wants to merge 1 commit into
Open
fix: EgovIndexFileWriter 가 초기 파일명 생성 시 지정한 확장자를 .csv 로 대체하는 문제 수정#363wantaekchoi wants to merge 1 commit into
wantaekchoi wants to merge 1 commit into
Conversation
configureWriterIndexResouce() 가 검증하는 파일명 규칙은
"파일명" + "_NDX" + "(순번)" + ".확장자" 이고, (순번) 앞부분은 [a-zA-Z0-9_]+ 로
제한돼 점을 포함할 수 없다. 그런데 generateInitialIndexFilename() 은 확장자를
괄호 앞부분에서 찾으므로 lastIndexOf('.') 가 항상 -1 이 되어, 지정한 확장자를
인식하지 못하고 늘 ".csv" 로 대체한다.
기존 파일이 있을 때 쓰이는 generateNewIndexFilename() 은 (순번) 뒷부분을
확장자로 보존하므로, (+1) 옵션의 같은 설정이 디렉토리 상태에 따라 서로 다른
확장자를 만든다. 초기 파일명도 규칙대로 (순번) 뒷부분을 확장자로 사용하도록
맞춘다. 확장자를 생략한 경우에도 규칙 4) 와 같이 확장자를 붙이지 않는다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
EgovIndexFileWriter가 (+1) 옵션으로 초기 파일명을 만들 때indexResource에 지정한 확장자를 쓰지 않고.csv로 바꿉니다.같은 클래스가
configureWriterIndexResouce()에서 검증하는 파일명 규칙은 확장자를(순번)뒤에 둡니다.(앞부분은[a-zA-Z0-9_]+라서 점을 포함할 수 없는데,generateInitialIndexFilename()은 확장자를 괄호 앞부분에서 찾습니다. 199줄 정규식을 통과한 값만 251줄에서 이 메서드로 가므로baseFileName.lastIndexOf('.')는 항상 -1 이고else의.csv만 남습니다.기존 파일이 있을 때 쓰이는 형제 경로
generateNewIndexFilename()은 규칙대로 일련번호 뒷부분에서 확장자를 가져옵니다.그래서 같은
indexResource설정이 디렉토리 상태에 따라 다른 확장자를 만듭니다.DATA_NDX(+1).txt를 지정해도 빈 디렉토리의 첫 실행은.csv를 만들고, 형제 경로가 그.csv를 이어받으므로 이후로도.txt는 나오지 않습니다. 반대로.txt파일이 이미 있는 디렉토리에서는.txt가 유지됩니다.동작이 바뀌는 지점
저장소 자체 테스트 잡
DelimitedToDelimitedJobIndexReaderJob.java:68의writer.setIndexResource("target/test-outputs/csvData_NDX(+1)")는 확장자를 지정하지 않아target/test-outputs가 비어 있는 첫 실행에서 산출 파일명이 바뀝니다. 실측 결과 수정 전에는csvData_NDX_20260903104941.csv, 수정 후에는csvData_NDX_20260903105007로 확장자가 붙지 않습니다. (각각 디렉토리를 비운 뒤 실행해 측정했고, 14자리 숫자는 실행 시각입니다.)두 번째 실행부터는
generateNewIndexFilename()경로라 기존 파일의 확장자를 그대로 이어받습니다.확장자를 붙이지 않는 쪽이 규칙에 맞다고 본 근거는 규칙 4) 가 확장자 생략을 허용한다는 점, 그리고 형제 경로도 순번 뒤가 비면
extValue = ""로 두어 확장자를 붙이지 않는다는 점입니다.확장자가 비어 있을 때만
.csv를 유지하는 좁은 수정은,csvData_NDX(+1)이 빈 디렉토리에서는.csv, 확장자 없는 파일이 있는 디렉토리에서는 확장자 없음이 되어 디렉토리 상태 의존이 남으므로 택하지 않았습니다.AS-IS / TO-BE
private String generateInitialIndexFilename(String resourceFileName) { - // 파일명에서 확장자 추출 (괄호 이전 부분에서) - String baseFileName = resourceFileName; - int parenIndex = resourceFileName.indexOf('('); - if (parenIndex > 0) { - baseFileName = resourceFileName.substring(0, parenIndex); - } - + // 파일명 규칙("파일명" + "_NDX" + "(순번)" + ".확장자")에 따라 (순번) 뒷부분을 확장자로 사용한다. String extension = ""; - int lastDotIndex = baseFileName.lastIndexOf('.'); - if (lastDotIndex > 0) { - extension = baseFileName.substring(lastDotIndex); - } else { - // 확장자가 없으면 기본적으로 .csv 사용 - extension = ".csv"; + int closeParenIndex = resourceFileName.indexOf(')'); + if (closeParenIndex > 0) { + extension = resourceFileName.substring(closeParenIndex + 1); }indexOf(')')가 -1 인 입력은 199줄 정규식이 251줄 전에 걸러내지만 기존 코드의if (... > 0)방어 형태는 그대로 두었습니다.영향 범위
generateInitialIndexFilename()호출부는configureWriterIndexResouce():251한 곳뿐이고 진입 조건은 249줄의indexKeyNo == 1 && (ArrayUtils.isEmpty(fileInfoList) || fileInfoList.length == 0)입니다. (+1) 옵션이면서 대상 디렉토리에 인덱스 파일이 없는 첫 실행에만 해당하고 형제 경로generateNewIndexFilename()은 손대지 않았습니다.JUnit 테스트 JUnit tests
EgovIndexFileWriterInitialExtensionTest를 더했습니다. 공개 진입점@BeforeStep beforeStep()으로 구동해 확장자를 지정한 경우, 생략한 경우, 기존 파일이 있는 형제 경로 세 가지를 봅니다.수정 전 코드로 되돌려 모듈 전체를 돌리면 앞의 두 건이 실패합니다.
수정 후 모듈 전체입니다.
EgovIndexFileWriter를 직접 쓰는EgovIndexFileWriterResourceLoaderTest와 위 잡을 컨텍스트로 실행하는EgovIndexFileReaderWriterTest도 통과합니다.테스트 브라우저 Test Browser
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
화면이 없는 실행환경 모듈이라 첨부하지 않았습니다.