Skip to content

Commit

Permalink
windows: avoid breaking LibC.getuid call
Browse files Browse the repository at this point in the history
fixes #291
  • Loading branch information
will committed Nov 5, 2024
1 parent cafeeb2 commit cafef48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/pq/conninfo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cafef48

Please sign in to comment.