Skip to content

Commit

Permalink
FEXRootFSFetcher: Fixes some extract logic
Browse files Browse the repository at this point in the history
`Extract` was never set to false even if the user said not to overwrite.
Ensure that if the user decided not to overwrite an existing folder,
that it returns false so it correctly doesn't overwrite the folder.
  • Loading branch information
Sonicadvance1 committed Sep 9, 2024
1 parent b732f7d commit 231b16d
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions Source/Tools/FEXRootFSFetcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,60 +1032,53 @@ namespace UnSquash {
bool UnsquashRootFS(const fextl::string& Path, const fextl::string& RootFS, const fextl::string& FolderName) {
auto TargetFolder = Path + FolderName;

bool Extract = true;
std::error_code ec;
if (std::filesystem::exists(TargetFolder, ec)) {
fextl::string Question = "Target folder \"" + FolderName + "\" already exists. Overwrite?";
if (AskForConfirmation(Question)) {
if (std::filesystem::remove_all(TargetFolder, ec) != ~0ULL) {
Extract = true;
if (std::filesystem::remove_all(TargetFolder, ec) == ~0ULL) {
ExecWithInfo("Couldn't remove previous directory. Won't extract.");
return false;
}
} else {
return false;
}
}

if (Extract) {
const std::vector<const char*> ExecveArgs = {
"unsquashfs", "-f", "-d", TargetFolder.c_str(), RootFS.c_str(), nullptr,
};

return Exec::ExecAndWaitForResponse(ExecveArgs[0], const_cast<char* const*>(ExecveArgs.data())) == 0;
}
const std::vector<const char*> ExecveArgs = {
"unsquashfs", "-f", "-d", TargetFolder.c_str(), RootFS.c_str(), nullptr,
};

return false;
return Exec::ExecAndWaitForResponse(ExecveArgs[0], const_cast<char* const*>(ExecveArgs.data())) == 0;
}

bool ExtractEroFS(const fextl::string& Path, const fextl::string& RootFS, const fextl::string& FolderName) {
auto TargetFolder = Path + FolderName;

bool Extract = true;
std::error_code ec;
if (std::filesystem::exists(TargetFolder, ec)) {
fextl::string Question = "Target folder \"" + FolderName + "\" already exists. Overwrite?";
if (AskForConfirmation(Question)) {
if (std::filesystem::remove_all(TargetFolder, ec) != ~0ULL) {
Extract = true;
}
if (ec) {
if (std::filesystem::remove_all(TargetFolder, ec) == ~0ULL) {
ExecWithInfo("Couldn't remove previous directory. Won't extract.");
return false;
}
} else {
return false;
}
}

if (Extract) {
ExecWithInfo("Extracting Erofs. This might take a few minutes.");
ExecWithInfo("Extracting Erofs. This might take a few minutes.");

const auto ExtractOption = fmt::format("--extract={}", TargetFolder);
const std::vector<const char*> ExecveArgs = {
"fsck.erofs",
ExtractOption.c_str(),
RootFS.c_str(),
nullptr,
};

return Exec::ExecAndWaitForResponse(ExecveArgs[0], const_cast<char* const*>(ExecveArgs.data())) == 0;
}
const auto ExtractOption = fmt::format("--extract={}", TargetFolder);
const std::vector<const char*> ExecveArgs = {
"fsck.erofs",
ExtractOption.c_str(),
RootFS.c_str(),
nullptr,
};

return false;
return Exec::ExecAndWaitForResponse(ExecveArgs[0], const_cast<char* const*>(ExecveArgs.data())) == 0;
}
} // namespace UnSquash

Expand Down

0 comments on commit 231b16d

Please sign in to comment.