add comment about known issues

This commit is contained in:
2026-09-01 08:35:44 +09:00
parent 2ef8ab0df6
commit 7c873e4382
+154 -134
View File
@@ -11,161 +11,181 @@ static uint32_t g_recursive_counter = 0;
bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::path &rootPath) bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::path &rootPath)
{ {
using namespace std; using namespace std;
bool bRet = true; bool bRet = true;
// path class obj 생성. // path class obj 생성.
filesystem::path pathObj(strInputPath); filesystem::path pathObj(strInputPath);
// file valid check // file valid check
if (!filesystem::exists(pathObj)) if (!filesystem::exists(pathObj))
{ {
printf("[ERROR](FileReader) Something went Wrong..!! \r\n"); printf("[ERROR](FileReader) Something went Wrong..!! \r\n");
printf("[ERROR] File not found : %s ", pathObj.string().c_str()); printf("[ERROR] File not found : %s ", pathObj.string().c_str());
bRet = false; bRet = false;
} }
enum class eFILETYPE enum class eFILETYPE
{ {
isFile, isDir, ETC isFile, isDir, ETC
}; };
// distinguish file type // distinguish file type
eFILETYPE eFileDist; eFILETYPE eFileDist;
if (filesystem::is_directory(pathObj)) eFileDist = eFILETYPE::isDir; if (filesystem::is_directory(pathObj)) eFileDist = eFILETYPE::isDir;
else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile; else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile;
else eFileDist = eFILETYPE::ETC; else eFileDist = eFILETYPE::ETC;
switch (eFileDist) switch (eFileDist)
{ {
// case 1 : input one file // case 1 : input one file
case eFILETYPE::isFile: case eFILETYPE::isFile:
{ {
// TODO : export to debugging log function // TODO : export to debugging log function
string strDbg = "[INFO] Current Entry (File)\t: " + pathObj.string(); string strDbg = "[INFO] Current Entry (File)\t: " + pathObj.string();
strDbg += "\t Counter : " + to_string(g_recursive_counter); strDbg += "\t Counter : " + to_string(g_recursive_counter);
strDbg += "\r\n"; strDbg += "\r\n";
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(), pathObj.generic_string());
break; break;
} }
// case 2 : input directory // case 2 : input directory
case eFILETYPE::isDir: case eFILETYPE::isDir:
{ {
// make iterator to traversal // make iterator to traversal
filesystem::directory_iterator itrDir(pathObj); filesystem::directory_iterator itrDir(pathObj);
g_recursive_counter++; g_recursive_counter++;
while (itrDir != filesystem::end(itrDir)) while (itrDir != filesystem::end(itrDir))
{ {
// get entry one by one // get entry one by one
const filesystem::directory_entry& currentEntry = *itrDir; const filesystem::directory_entry& currentEntry = *itrDir;
const filesystem::path& currentAbsPath = currentEntry.path(); const filesystem::path& currentAbsPath = currentEntry.path();
if (filesystem::is_directory(currentEntry)) if (filesystem::is_directory(currentEntry))
{ {
// TODO : export to debugging log function // TODO : export to debugging log function
string strDbg = "[INFO] Current Entry (Dir)\t: " + currentAbsPath.string(); string strDbg = "[INFO] Current Entry (Dir)\t: " + currentAbsPath.string();
strDbg += "\t Counter : " + to_string(g_recursive_counter); strDbg += "\t Counter : " + to_string(g_recursive_counter);
strDbg += "\r\n"; strDbg += "\r\n";
OutputDebugStringA(strDbg.c_str()); OutputDebugStringA(strDbg.c_str());
// recursive traversal // recursive traversal
// TODO : bRet 쓰는 곳이 없음. 파일 처리 실패 시 어떻게 할 건지 정해야 함. // TODO : bRet 쓰는 곳이 없음. 파일 처리 실패 시 어떻게 할 건지 정해야 함.
bRet = FileReader(zip, currentAbsPath.string(), rootPath); bRet = FileReader(zip, currentAbsPath.string(), rootPath);
} }
else if (filesystem::is_regular_file(currentEntry)) else if (filesystem::is_regular_file(currentEntry))
{ {
// TODO : export to debugging log function // TODO : export to debugging log function
string strDbg = "[INFO] Current Entry (File)\t: " + currentAbsPath.string(); string strDbg = "[INFO] Current Entry (File)\t: " + currentAbsPath.string();
strDbg += "\t Counter : " + to_string(g_recursive_counter); strDbg += "\t Counter : " + to_string(g_recursive_counter);
strDbg += "\r\n"; strDbg += "\r\n";
OutputDebugStringA(strDbg.c_str()); OutputDebugStringA(strDbg.c_str());
// archiving file // archiving file
auto relativePath = filesystem::relative(currentAbsPath, rootPath); auto relativePath = filesystem::relative(currentAbsPath, rootPath);
// generic_string : make back-slash to OS independant delimeter ("\\" -> "/") // generic_string : make back-slash to OS independant delimeter ("\\" -> "/")
// TODO : bRet 쓰는 곳이 없음. 파일 처리 실패 시 어떻게 할 건지 정해야 함. // TODO : bRet 쓰는 곳이 없음. 파일 처리 실패 시 어떻게 할 건지 정해야 함.
bRet = zip.AddFileToZip(currentAbsPath.generic_string(), relativePath.generic_string()); bRet = zip.AddFileToZip(currentAbsPath.generic_string(), relativePath.generic_string());
} }
else else
{ {
printf("[ERROR](FileReader) Something went Wrong..!! \r\n"); printf("[ERROR](FileReader) Something went Wrong..!! \r\n");
printf("[ERROR](FileReader) Maybe its corrupted file. \r\n"); printf("[ERROR](FileReader) Maybe its corrupted file. \r\n");
bRet = false; bRet = false;
} }
// step forward entry // step forward entry
itrDir++; itrDir++;
} }
g_recursive_counter--; g_recursive_counter--;
break; break;
} }
// case 3 : ERROR // case 3 : ERROR
case eFILETYPE::ETC: case eFILETYPE::ETC:
{ {
printf("[ERROR](FileReader) Something went Wrong..!! \r\n"); printf("[ERROR](FileReader) Something went Wrong..!! \r\n");
printf("[ERROR](FileReader) Maybe its corrupted file. \r\n"); printf("[ERROR](FileReader) Maybe its corrupted file. \r\n");
bRet = false; bRet = false;
break; break;
} }
default: default:
break; break;
}; };
// TODO : 실패 상황 별 다른 코드 부여? + 코드 별 처리 어떻게 할 건지? // TODO : 실패 상황 별 다른 코드 부여? + 코드 별 처리 어떻게 할 건지?
return bRet; return bRet;
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
using namespace std; /**
[-Known Issue-]
int iRet = 0; 1. 입력 경로의 상위 디렉터리 전체가 불필요하게 중첩 폴더로 생성되는 현상
printf("==================== Hello Zip! ====================\r\n"); - 현상 : 단일 파일 경로 지정 시, 드라이브 및 상위 디렉터리 계층(d:\MyCode\4_Doc\...)이
printf("=== Please enter Target Path ===\r\n"); 압축 파일 내부에 그대로 중첩 생성됨
printf("=== (FOR TEST, Input below) ===\r\n"); - 원인 : 입력 경로를 상대 경로로 정규화하지 않고 절대 경로 전체를 압축 내부 엔트리 경로로 사용
printf("=== (1 : File Test, 2 : Dir Test) ===\r\n"); - 기대값 : 입력 파일 (혹은 디렉토리) 만 압축되어 저장.
printf("====================================================\r\n");
2. 내부 상태 플래그 (bRet) 의 미구현
- 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 미구현
- 기대값 : 일반적인 error code 로써 동작하는 리턴 값으로 사용.
string strInputPath; 3. 별도 Unit Test 미구현
getline(cin, strInputPath); - 현상 : 프로젝트의 디버깅 및 테스트를 위해서는 프로그램의 전체 Work flow 를 따라가야 함.
- 기대값 : 단일 기능 (예 : CRC 값 검증, Output File 테스트) 을 테스트 하기 위한 Unit Test 구현
// Testing input */
if (stoi(strInputPath) == 1)
strInputPath = INPUT_FILE_NAME;
else if (stoi(strInputPath) == 2)
strInputPath = INPUT_DIR_NAME;
filesystem::path absPath = filesystem::absolute(strInputPath); using namespace std;
filesystem::path rootPath = absPath.parent_path();
// Main Zip archive method int iRet = 0;
MyZip zip; printf("==================== Hello Zip! ====================\r\n");
if (!FileReader(zip, strInputPath, rootPath)) printf("=== Please enter Target Path ===\r\n");
{ printf("=== (FOR TEST, Input below) ===\r\n");
printf("[ ERROR ](FileReader) Somthing went Wrong... \r\n"); printf("=== (1 : File Test, 2 : Dir Test) ===\r\n");
iRet = -1; printf("====================================================\r\n");
} printf("Input Path: ");
else
{
if (!zip.FinalizeZip())
{
printf("[ ERROR ](Finallize) Somthing went Wrong... \r\n");
iRet = -1;
}
else
{
printf("It Works Fine. \r\n");
printf("==================== Good Bye Zip! =================\r\n");
iRet = 0;
}
}
return iRet; string strInputPath;
getline(cin, strInputPath);
// Testing input
if (strInputPath == "1")
strInputPath = INPUT_FILE_NAME;
else if (strInputPath == "2")
strInputPath = INPUT_DIR_NAME;
filesystem::path absPath = filesystem::absolute(strInputPath);
filesystem::path rootPath = absPath.parent_path();
// Main Zip archive method
MyZip zip;
if (!FileReader(zip, strInputPath, rootPath))
{
printf("[ ERROR ](FileReader) Somthing went Wrong... \r\n");
iRet = -1;
}
else
{
if (!zip.FinalizeZip())
{
printf("[ ERROR ](Finallize) Somthing went Wrong... \r\n");
iRet = -1;
}
else
{
printf("It Works Fine. \r\n");
printf("==================== Good Bye Zip! =================\r\n");
iRet = 0;
}
}
return iRet;
} }