Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 114a86eb authored by David Anderson's avatar David Anderson Committed by Android (Google) Code Review
Browse files

Merge "libdm: Fix WaitForFile early-returning on failed accesses." into rvc-dev

parents bbbd1a8e 44ae5460
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ bool DeviceMapper::DeleteDevice(const std::string& name,
        return false;
    }
    if (!WaitForFileDeleted(unique_path, timeout_ms)) {
        LOG(ERROR) << "Timeout out waiting for " << unique_path << " to be deleted";
        LOG(ERROR) << "Failed waiting for " << unique_path << " to be deleted";
        return false;
    }
    return true;
@@ -161,7 +161,7 @@ bool DeviceMapper::CreateDevice(const std::string& name, const DmTable& table, s
        return true;
    }
    if (!WaitForFile(unique_path, timeout_ms)) {
        LOG(ERROR) << "Timed out waiting for device path: " << unique_path;
        LOG(ERROR) << "Failed waiting for device path: " << unique_path;
        DeleteDevice(name);
        return false;
    }
+12 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@

#include <thread>

#include <android-base/logging.h>

using namespace std::literals;

namespace android {
@@ -45,7 +47,11 @@ bool WaitForFile(const std::string& path, const std::chrono::milliseconds& timeo
        // If the file exists but returns EPERM or something, we consider the
        // condition met.
        if (access(path.c_str(), F_OK) != 0) {
            if (errno == ENOENT) return WaitResult::Wait;
            if (errno == ENOENT) {
                return WaitResult::Wait;
            }
            PLOG(ERROR) << "access failed: " << path;
            return WaitResult::Fail;
        }
        return WaitResult::Done;
    };
@@ -54,9 +60,13 @@ bool WaitForFile(const std::string& path, const std::chrono::milliseconds& timeo

bool WaitForFileDeleted(const std::string& path, const std::chrono::milliseconds& timeout_ms) {
    auto condition = [&]() -> WaitResult {
        if (access(path.c_str(), F_OK) == 0 || errno != ENOENT) {
        if (access(path.c_str(), F_OK) == 0) {
            return WaitResult::Wait;
        }
        if (errno != ENOENT) {
            PLOG(ERROR) << "access failed: " << path;
            return WaitResult::Fail;
        }
        return WaitResult::Done;
    };
    return WaitForCondition(condition, timeout_ms);