ファイル書き込み時のエラーは直ちにFAILするように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@351 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-06-30 01:09:19 +00:00
parent 82ee9cbffa
commit 5b566a9202

View File

@ -153,7 +153,6 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
nn::Result result;
bool ret_value = true;
// ファイル作成
nn::fs::FileInputStream from_file;
nn::fs::FileStream to_file;
@ -169,7 +168,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
else
{
@ -178,7 +177,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
else
{
@ -200,7 +199,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
// フルパスをハッシュに含める
@ -218,8 +217,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
result = to_file.TryWrite(&writeSize, &enc, sizeof(enc), false);
if (result.IsFailure())
{
ret_value = false;
return ret_value;
return false;
}
while (1)
@ -231,8 +229,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return ret_value;
return false;
}
else
{
@ -252,7 +249,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
result = to_file.TryFlush();
@ -260,7 +257,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
break;
@ -290,7 +287,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
}
@ -301,7 +298,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b
}
from_file.Finalize();
return ret_value;
return true;
}
@ -313,7 +310,6 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
s32 numread = 0;
std::wostringstream target_from;
std::wostringstream target_to;
bool ret_value = true;
nn::Result result = from_dir.TryInitialize(from_path);
@ -372,13 +368,13 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
// 再帰処理
if (!CopyDirectory(fileList, target_from.str().c_str(), target_to.str().c_str(), buf, bufSize, encode, list, listContext))
{
ret_value = false;
return false;
}
}
else
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
}
// ファイルの場合
@ -413,7 +409,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
else
{
@ -422,7 +418,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
else
{
@ -449,7 +445,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
// フルパスをハッシュに含める
@ -467,8 +463,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
result = to_file.TryWrite(&writeSize, &enc, sizeof(enc), false);
if (result.IsFailure())
{
ret_value = false;
continue;
return false;
}
}
else
@ -484,8 +479,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
continue;
return false;
}
swAesCtrContext.Decrypt(&dec, &header, sizeof(header));
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
@ -499,7 +493,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
}
@ -512,8 +506,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
break;
return false;
}
else
{
@ -535,7 +528,8 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
}
@ -544,7 +538,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
// 復号済みなら検証する
@ -554,7 +548,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
buf, bufSize, target_from.str().c_str(), target_tmp.str().c_str(),
target_to.str().c_str()))
{
ret_value = false;
return false;
}
}
@ -616,7 +610,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
result = to_file.TryFlush();
if (result.IsFailure())
{
ret_value = false;
return false;
}
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
@ -625,7 +619,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
target_from.str().c_str(), target_tmp.str().c_str(),
target_to.str().c_str()))
{
ret_value = false;
return false;
}
break;
}
@ -634,7 +628,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
}
@ -645,16 +639,10 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
}
from_file.Finalize();
}
// 1ファイルごとの結果確認
if(!ret_value)
{
break;
}
}
from_dir.Finalize();
return ret_value;
return true;
}
u32 GetProgress()
@ -742,7 +730,7 @@ bool VerifyMac(nn::fs::FileInputStream* sdFile, nn::fs::FileStream* nandFile, s6
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
context.Update(&enc, sizeof(enc));
bool ret_value = false;
bool retValue = false;
size_t totalReadSize = 0;
while (1)
@ -753,14 +741,14 @@ bool VerifyMac(nn::fs::FileInputStream* sdFile, nn::fs::FileStream* nandFile, s6
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
retValue = false;
break;
}
else
{
if (readSize == 0)
{
ret_value = CalculateAndCompareCmac(&context, sdCmac);
retValue = CalculateAndCompareCmac(&context, sdCmac);
break;
}
else
@ -774,7 +762,8 @@ bool VerifyMac(nn::fs::FileInputStream* sdFile, nn::fs::FileStream* nandFile, s6
if (result.IsFailure())
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
retValue = false;
break;
}
}
}
@ -782,7 +771,7 @@ bool VerifyMac(nn::fs::FileInputStream* sdFile, nn::fs::FileStream* nandFile, s6
nn::crypto::Finalize();
nandFile->Finalize();
return ret_value;
return retValue;
}
bool ConfirmFile(nn::fs::FileInputStream* from_file, nn::fs::FileStream* to_file, s64 sdFileSize, s64 nandFileSize,
@ -790,7 +779,6 @@ bool ConfirmFile(nn::fs::FileInputStream* from_file, nn::fs::FileStream* to_file
{
nn::Result result;
bool ret_value = true;
NN_LOG("Verify CMAC %ls\n", sdPath);
if (!VerifyMac(from_file, to_file, sdFileSize, nandFileSize, truePath, buf, bufSize))
{
@ -799,13 +787,18 @@ bool ConfirmFile(nn::fs::FileInputStream* from_file, nn::fs::FileStream* to_file
COMMON_LOGGER("**********Verification Failed %s, Delete**********\n", GetCharStr(sdPath));
result = nn::fs::TryDeleteFile(tmpPath);
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
ret_value = false;
return false;
}
else
{
NN_LOG("Verification Success %s, Rename\n", GetCharStr(sdPath));
// 書き込み先を削除する
result = nn::fs::TryDeleteFile(truePath);
if (result.IsFailure() && !nn::fs::ResultNotFound::Includes(result))
{
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
return false;
}
// 正しいファイル名にリネームする
result = nn::fs::TryRenameFile(tmpPath, truePath);
@ -813,11 +806,11 @@ bool ConfirmFile(nn::fs::FileInputStream* from_file, nn::fs::FileStream* to_file
if (result.IsFailure())
{
s_FinishedFileSize -= nandFileSize;
ret_value = false;
return false;
}
}
return ret_value;
return true;
}
//! @brief 入力データの末尾16バイトをPKCS5で必要バイト数パディングする