diff --git a/src/util/secure_vault.cpp b/src/util/secure_vault.cpp index b56211f..e8a885c 100644 --- a/src/util/secure_vault.cpp +++ b/src/util/secure_vault.cpp @@ -13,6 +13,11 @@ #include #include "../util/logger.h" +#ifndef _WIN32 +#include +#include +#endif + namespace fs = std::filesystem; namespace dragonx { @@ -232,6 +237,15 @@ bool SecureVault::removeVault() { std::ofstream zap(vaultPath, std::ios::binary); if (zap.is_open()) { zap.write(reinterpret_cast(zeros.data()), sz); + zap.flush(); + zap.close(); + // Force the zeros to stable storage before unlinking — otherwise the + // write may never leave the OS cache (best-effort; not a guarantee on + // CoW/journaling filesystems or wear-leveling SSDs). +#ifndef _WIN32 + int fd = ::open(vaultPath.c_str(), O_WRONLY); + if (fd >= 0) { ::fsync(fd); ::close(fd); } +#endif } } }