add file write exception
This commit is contained in:
+2
-1
@@ -75,4 +75,5 @@ ipch/
|
|||||||
# Zip Foramt Test
|
# Zip Foramt Test
|
||||||
Test*
|
Test*
|
||||||
!TestFiles
|
!TestFiles
|
||||||
*.zip
|
*.zip
|
||||||
|
Docs/
|
||||||
+30
-2
@@ -91,11 +91,20 @@ bool MyZip::FinalizeZip()
|
|||||||
this->EOCDR.numOfCentralDir = static_cast<uint16_t>(vecEntries.size());
|
this->EOCDR.numOfCentralDir = static_cast<uint16_t>(vecEntries.size());
|
||||||
this->EOCDR.numOfEntries = static_cast<uint16_t>(vecEntries.size());
|
this->EOCDR.numOfEntries = static_cast<uint16_t>(vecEntries.size());
|
||||||
this->EOCDR.lengthOfCommentLength = 0;
|
this->EOCDR.lengthOfCommentLength = 0;
|
||||||
|
this->EOCDR.sizeOfCentralDir = 0;
|
||||||
|
|
||||||
for (const auto &p : vecEntries)
|
for (const auto &p : vecEntries)
|
||||||
{
|
{
|
||||||
this->EOCDR.sizeOfCentralDir += (sizeof(p.header) + p.header.lengthOfFileName);
|
this->EOCDR.sizeOfCentralDir += (sizeof(p.header) + p.header.lengthOfFileName);
|
||||||
}
|
}
|
||||||
this->EOCDR.offsetCentralDir = static_cast<uint32_t>(fileOut.tellp());
|
|
||||||
|
auto offset = static_cast<uint32_t>(fileOut.tellp());
|
||||||
|
if (offset == static_cast<std::streampos>(-1))
|
||||||
|
{
|
||||||
|
printf("[ ERROR ](FinalizeZip) Failed to get offset");
|
||||||
|
fileOut.close();
|
||||||
|
}
|
||||||
|
this->EOCDR.offsetCentralDir = static_cast<uint32_t>(offset);
|
||||||
|
|
||||||
// Write to file (archiving)
|
// Write to file (archiving)
|
||||||
for (const auto &p : vecEntries)
|
for (const auto &p : vecEntries)
|
||||||
@@ -103,12 +112,31 @@ bool MyZip::FinalizeZip()
|
|||||||
// CentralDirectory, file name (var)
|
// CentralDirectory, file name (var)
|
||||||
fileOut.write(reinterpret_cast<const char *>(&p.header), sizeof(p.header));
|
fileOut.write(reinterpret_cast<const char *>(&p.header), sizeof(p.header));
|
||||||
fileOut.write(p.fileName.c_str(), p.header.lengthOfFileName);
|
fileOut.write(p.fileName.c_str(), p.header.lengthOfFileName);
|
||||||
|
|
||||||
|
if (fileOut.fail())
|
||||||
|
{
|
||||||
|
printf("[ ERROR ](FinalizeZip) Disk write failed while writing central directory entries (Disk full?)\n");
|
||||||
|
fileOut.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of CentralDirectory Record
|
// fileOut 예외처리 추가
|
||||||
fileOut.write(reinterpret_cast<const char *>(&this->EOCDR), sizeof(this->EOCDR));
|
fileOut.write(reinterpret_cast<const char *>(&this->EOCDR), sizeof(this->EOCDR));
|
||||||
|
if (fileOut.fail())
|
||||||
|
{
|
||||||
|
printf("[ ERROR ](FinalizeZip) Disk write failed while writing EOCDR\n");
|
||||||
|
fileOut.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileOut 예외처리 추가
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
if (fileOut.fail())
|
||||||
|
{
|
||||||
|
printf("[ ERROR ](FinalizeZip) Failed to close/flush file (Disk full?)\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : 성공여부 처리 어떻게 할 건지?
|
// TODO : 성공여부 처리 어떻게 할 건지?
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
// Zip 마무리
|
// Zip 마무리
|
||||||
bool FinalizeZip();
|
bool FinalizeZip();
|
||||||
|
|
||||||
|
private:
|
||||||
// Header Functions
|
// Header Functions
|
||||||
void FillLocalFileHeader(LocalFileHeader &targetLF, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
|
void FillLocalFileHeader(LocalFileHeader &targetLF, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
|
||||||
CentralDirectory GetFilledCentDirHeader(CentralDirectory &targetCDH, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
|
CentralDirectory GetFilledCentDirHeader(CentralDirectory &targetCDH, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
|
||||||
|
|||||||
+15
-3
@@ -48,7 +48,7 @@ bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::pat
|
|||||||
OutputDebugStringA(strDbg.c_str());
|
OutputDebugStringA(strDbg.c_str());
|
||||||
|
|
||||||
auto absPathOjb = filesystem::absolute(pathObj);
|
auto absPathOjb = filesystem::absolute(pathObj);
|
||||||
bRet = zip.AddFileToZip(absPathOjb.generic_string(), pathObj.generic_string());
|
bRet = zip.AddFileToZip(absPathOjb.generic_string(), rootPath.generic_string());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -133,11 +133,23 @@ int main(int argc, char* argv[])
|
|||||||
- 원인 : 입력 경로를 상대 경로로 정규화하지 않고 절대 경로 전체를 압축 내부 엔트리 경로로 사용
|
- 원인 : 입력 경로를 상대 경로로 정규화하지 않고 절대 경로 전체를 압축 내부 엔트리 경로로 사용
|
||||||
- 기대값 : 입력 파일 (혹은 디렉토리) 만 압축되어 저장.
|
- 기대값 : 입력 파일 (혹은 디렉토리) 만 압축되어 저장.
|
||||||
|
|
||||||
2. 내부 상태 플래그 (bRet) 의 미구현
|
2. 폴더 순회구조의 문제
|
||||||
|
- 문제 : 전역변수(g_recursive_counter)및 함수(FileReader) 의 전역사용
|
||||||
|
- 기대값 : 폴더 순회구조 또한 클래스화
|
||||||
|
|
||||||
|
3. CentralDirectory 설계문제
|
||||||
|
- 문제 : CentralDirectory 를 채우는 코드가 분산됨.
|
||||||
|
- 기대값 : 한 곳으로 집중.
|
||||||
|
|
||||||
|
4. 내부 상태 플래그 (bRet) 의 미구현
|
||||||
- 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 미구현
|
- 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 미구현
|
||||||
- 기대값 : 일반적인 error code 로써 동작하는 리턴 값으로 사용.
|
- 기대값 : 일반적인 error code 로써 동작하는 리턴 값으로 사용.
|
||||||
|
|
||||||
3. 별도 Unit Test 미구현
|
5. 예외처리 설계 및 구현의 부재
|
||||||
|
- 현상 : File I/O, 경로검사 등 일관된 형식의 예외처리와 Message 처리가 없음.
|
||||||
|
- 기대값 : 에러 조기발견
|
||||||
|
|
||||||
|
5. 별도 Unit Test 미구현
|
||||||
- 현상 : 프로젝트의 디버깅 및 테스트를 위해서는 프로그램의 전체 Work flow 를 따라가야 함.
|
- 현상 : 프로젝트의 디버깅 및 테스트를 위해서는 프로그램의 전체 Work flow 를 따라가야 함.
|
||||||
- 기대값 : 단일 기능 (예 : CRC 값 검증, Output File 테스트) 을 테스트 하기 위한 Unit Test 구현
|
- 기대값 : 단일 기능 (예 : CRC 값 검증, Output File 테스트) 을 테스트 하기 위한 Unit Test 구현
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user