Skip to content

Commit 534b301

Browse files
authored
Merge pull request #154 from rofinn/rf/missing-user
Only warn if gid or uid can't be found
2 parents 80e49ae + ebea92e commit 534b301

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/libc.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ Base.show(io::IO, user::User) = print(io, "$(user.uid) ($(user.name))")
8181
ret = Libc.errno()
8282

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

86-
return User(ps)
85+
if ps == C_NULL
86+
@warn "User $uid not found."
87+
return User("NA", uid, uid, "NA", "NA")
88+
else
89+
return User(ps)
90+
end
8791
end
8892

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

121125
systemerror(:getgrgid, !iszero(ret))
122-
gr == C_NULL && throw(ArgumentError("Group $gid not found."))
123-
return Group(gr)
126+
if gr == C_NULL
127+
@warn "Group $gid not found."
128+
return Group("NA", gid)
129+
else
130+
return Group(gr)
131+
end
124132
end
125133

126134
Group() = Group(UInt(ccall(:getegid, Cint, ())))

test/system.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ ps = PathSet(; symlink=true)
293293
@test g_int isa FilePathsBase.Group
294294
@test u_int.uid isa Unsigned
295295
@test g_int.gid isa Unsigned
296+
297+
# Non-existent user or group on unix
298+
if Sys.isunix()
299+
u_int = FilePathsBase.User(UInt(9999))
300+
g_int = FilePathsBase.Group(UInt(9999))
301+
@test u_int isa FilePathsBase.User
302+
@test g_int isa FilePathsBase.Group
303+
@test u_int.uid == UInt(9999)
304+
@test g_int.gid == UInt(9999)
305+
@test u_int.name == "NA"
306+
@test g_int.name == "NA"
307+
end
296308
end
297309
end
298310

0 commit comments

Comments
 (0)