Repository: microsoft/PowerToys
File: src/Update/PowerToys.Update.cpp (C++)

Code before:
        std::wstring parameters = L"/passive /norestart";
        sei.lpParameters = parameters.c_str();

        success = ShellExecuteExW(&sei) == TRUE;

        // Wait for the install completion
        if (success)
        {
            WaitForSingleObject(sei.hProcess, INFINITE);
            DWORD exitCode = 0;
            GetExitCodeProcess(sei.hProcess, &exitCode);
            success = exitCode == 0;
            CloseHandle(sei.hProcess);
        }
    }

    // Delete only .msi and .exe
    // Skip the installer if installation failed
    for (const auto& entry : fs::directory_iterator(updating::get_pending_updates_path()))
    {
        auto entryPath = entry.path().wstring();
        std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);

        if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
        {
            if (installer_path.find(entryPath) != std::string::npos && !success)
            {
                continue;
            }

            std::error_code err;
            fs::remove(entry, err);
            if (err.value())
            {
                Logger::warn("Failed to delete file {}. {}", entry.path().string(), err.message());
            }
        }
    }

    if (!success)
    {
        return false;
    }

    UpdateState::store([&](UpdateState& state) {
        state = {};
        state.githubUpdateLastCheckedDate.emplace(timeutil::now());
        state.state = UpdateState::upToDate;
    });

    if (launch_powertoys)

Review comment (bug):
```suggestion
// Skipping installer files of current update in case of update has failed.
            if (installer_path.find(entryPath) != std::string::npos && !success)
```


Code after:
        std::wstring parameters = L"/passive /norestart";
        sei.lpParameters = parameters.c_str();

        success = ShellExecuteExW(&sei) == TRUE;

        // Wait for the install completion
        if (success)
        {
            WaitForSingleObject(sei.hProcess, INFINITE);
            DWORD exitCode = 0;
            GetExitCodeProcess(sei.hProcess, &exitCode);
            success = exitCode == 0;
            CloseHandle(sei.hProcess);
        }
    }

    for (const auto& entry : fs::directory_iterator(updating::get_pending_updates_path()))
    {
        auto entryPath = entry.path().wstring();
        std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);

        // Delete only .msi and .exe
        if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
        {
            // Skipping current installer in case of failed update
            if (installer_path.find(entryPath) != std::string::npos && !success)
            {
                continue;
            }

            std::error_code err;
            fs::remove(entry, err);
            if (err.value())
            {
                Logger::warn("Failed to delete file {}. {}", entry.path().string(), err.message());
            }
        }
    }

    if (!success)
    {
        return false;
    }

    UpdateState::store([&](UpdateState& state) {
        state = {};
        state.githubUpdateLastCheckedDate.emplace(timeutil::now());
        state.state = UpdateState::upToDate;
    });

    if (launch_powertoys)