From cafef48da761e6e7fc4e008cdcdc41b988350ac1 Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Thu, 31 Oct 2024 10:30:36 +0100 Subject: [PATCH] windows: avoid breaking LibC.getuid call fixes #291 --- CHANGELOG | 1 + src/pq/conninfo.cr | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b9c8b80a..f4867ba9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v? upcoming * Support encoding PG::Interval params (thanks @Blacksmoke16) * Encode Crystal enum args as integers (thanks @jgaskins) * Handle Array(Bytes) encoding for query params containing non-Unicode text (thanks @jgaskins) +* Avoid calling LibC.getuid on windows v0.28.0 2023-12-21 diff --git a/src/pq/conninfo.cr b/src/pq/conninfo.cr index 728363dc..6e1b9223 100644 --- a/src/pq/conninfo.cr +++ b/src/pq/conninfo.cr @@ -171,7 +171,13 @@ module PQ end private def current_user_name - System::User.find_by(id: LibC.getuid.to_s).username + {% if flag?(:windows) %} + # NOTE: actually getting the current username on windows would be better + # https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getusernamew + "postgres" + {% else %} + System::User.find_by(id: LibC.getuid.to_s).username + {% end %} end end end