Skip to content

Commit

Permalink
Merge pull request #154 from rofinn/rf/missing-user
Browse files Browse the repository at this point in the history
Only warn if gid or uid can't be found
  • Loading branch information
rofinn authored Nov 24, 2021
2 parents 80e49ae + ebea92e commit 534b301
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ Base.show(io::IO, user::User) = print(io, "$(user.uid) ($(user.name))")
ret = Libc.errno()

systemerror(:getpwuid, !iszero(ret))
ps == C_NULL && throw(ArgumentError("User $uid not found."))

return User(ps)
if ps == C_NULL
@warn "User $uid not found."
return User("NA", uid, uid, "NA", "NA")
else
return User(ps)
end
end

User() = User(UInt(ccall(:geteuid, Cint, ())))
Expand Down Expand Up @@ -119,8 +123,12 @@ Base.show(io::IO, group::Group) = print(io, "$(group.gid) ($(group.name))")
ret = Libc.errno()

systemerror(:getgrgid, !iszero(ret))
gr == C_NULL && throw(ArgumentError("Group $gid not found."))
return Group(gr)
if gr == C_NULL
@warn "Group $gid not found."
return Group("NA", gid)
else
return Group(gr)
end
end

Group() = Group(UInt(ccall(:getegid, Cint, ())))
Expand Down
12 changes: 12 additions & 0 deletions test/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ ps = PathSet(; symlink=true)
@test g_int isa FilePathsBase.Group
@test u_int.uid isa Unsigned
@test g_int.gid isa Unsigned

# Non-existent user or group on unix
if Sys.isunix()
u_int = FilePathsBase.User(UInt(9999))
g_int = FilePathsBase.Group(UInt(9999))
@test u_int isa FilePathsBase.User
@test g_int isa FilePathsBase.Group
@test u_int.uid == UInt(9999)
@test g_int.gid == UInt(9999)
@test u_int.name == "NA"
@test g_int.name == "NA"
end
end
end

Expand Down

2 comments on commit 534b301

@rofinn
Copy link
Owner Author

@rofinn rofinn commented on 534b301 Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/49346

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.17 -m "<description of version>" 534b301662a8ef743a84b8bfe9d87f6a612c7641
git push origin v0.9.17

Please sign in to comment.