Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
72782230
E
Exa
项目概览
vnotepad
/
Exa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Exa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
72782230
编写于
6月 27, 2014
作者:
B
Ben S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor user/group code to be less indented
上级
b337f917
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
36 deletion
+43
-36
file.rs
file.rs
+8
-4
unix.rs
unix.rs
+35
-32
未找到文件。
file.rs
浏览文件 @
72782230
...
...
@@ -116,13 +116,17 @@ impl<'a> File<'a> {
// Display the ID if the user/group doesn't exist, which
// usually means it was deleted but its files weren't.
User
=>
{
let
style
=
if
unix
.uid
==
self
.stat.unstable.uid
as
u32
{
Yellow
.bold
()
}
else
{
Plain
};
let
string
=
unix
.get_user_name
(
self
.stat.unstable.uid
as
u32
)
.unwrap_or
(
self
.stat.unstable.uid
.to_str
());
let
uid
=
self
.stat.unstable.uid
as
u32
;
unix
.load_user
(
uid
);
let
style
=
if
unix
.uid
==
uid
{
Yellow
.bold
()
}
else
{
Plain
};
let
string
=
unix
.get_user_name
(
uid
)
.unwrap_or
(
uid
.to_str
());
style
.paint
(
string
.as_slice
())
},
Group
=>
{
let
name
=
unix
.get_group_name
(
self
.stat.unstable.gid
as
u32
)
.unwrap_or
(
self
.stat.unstable.gid
.to_str
());
let
style
=
if
unix
.is_group_member
(
self
.stat.unstable.gid
as
u32
)
{
Yellow
.normal
()
}
else
{
Plain
};
let
gid
=
self
.stat.unstable.gid
as
u32
;
unix
.load_group
(
gid
);
let
name
=
unix
.get_group_name
(
gid
)
.unwrap_or
(
gid
.to_str
());
let
style
=
if
unix
.is_group_member
(
gid
)
{
Yellow
.normal
()
}
else
{
Plain
};
style
.paint
(
name
.as_slice
())
},
}
...
...
unix.rs
浏览文件 @
72782230
...
...
@@ -73,20 +73,27 @@ impl Unix {
}
}
pub
fn
get_user_name
(
&
self
,
uid
:
u32
)
->
Option
<
String
>
{
self
.user_names
.get
(
&
uid
)
.clone
()
}
pub
fn
get_group_name
(
&
self
,
gid
:
u32
)
->
Option
<
String
>
{
self
.group_names
.get
(
&
gid
)
.clone
()
}
pub
fn
is_group_member
(
&
self
,
gid
:
u32
)
->
bool
{
*
self
.groups
.get
(
&
gid
)
}
pub
fn
get_user_name
(
&
mut
self
,
uid
:
u32
)
->
Option
<
String
>
{
self
.user_names
.find_or_insert_with
(
uid
,
|
&
u
|
{
let
pw
=
unsafe
{
c
::
getpwuid
(
u
as
i32
)
};
if
pw
.is_not_null
()
{
return
unsafe
{
Some
(
from_c_str
(
read
(
pw
)
.pw_name
))
};
}
else
{
return
None
;
}
})
.clone
()
pub
fn
load_user
(
&
mut
self
,
uid
:
u32
)
{
let
pw
=
unsafe
{
c
::
getpwuid
(
uid
as
i32
)
};
if
pw
.is_not_null
()
{
let
username
=
unsafe
{
Some
(
from_c_str
(
read
(
pw
)
.pw_name
))
};
self
.user_names
.insert
(
uid
,
username
);
}
else
{
self
.user_names
.insert
(
uid
,
None
);
}
}
fn
group_membership
(
group
:
**
i8
,
uname
:
&
String
)
->
bool
{
...
...
@@ -113,32 +120,28 @@ impl Unix {
}
}
pub
fn
get_group_name
(
&
mut
self
,
gid
:
u32
)
->
Option
<
String
>
{
match
self
.group_names
.find_copy
(
&
gid
)
{
Some
(
name
)
=>
name
,
pub
fn
load_group
(
&
mut
self
,
gid
:
u32
)
{
match
unsafe
{
c
::
getgrgid
(
gid
)
.to_option
()
}
{
None
=>
{
match
unsafe
{
c
::
getgrgid
(
gid
)
.to_option
()
}
{
None
=>
{
self
.group_names
.insert
(
gid
,
None
);
return
None
;
},
Some
(
r
)
=>
{
let
group_name
=
unsafe
{
Some
(
from_c_str
(
r
.gr_name
))
};
self
.group_names
.insert
(
gid
,
group_name
.clone
());
// Calculate whether we are a member of the
// group. Now's as good a time as any as we've
// just retrieved the group details.
if
!
self
.groups
.contains_key
(
&
gid
)
{
self
.groups
.insert
(
gid
,
Unix
::
group_membership
(
r
.gr_mem
,
&
self
.username
));
}
return
group_name
;
}
self
.group_names
.insert
(
gid
,
None
);
self
.groups
.insert
(
gid
,
false
);
},
Some
(
r
)
=>
{
let
group_name
=
unsafe
{
Some
(
from_c_str
(
r
.gr_name
))
};
self
.group_names
.insert
(
gid
,
group_name
.clone
());
// Calculate whether we are a member of the
// group. Now's as good a time as any as we've
// just retrieved the group details.
if
!
self
.groups
.contains_key
(
&
gid
)
{
self
.groups
.insert
(
gid
,
Unix
::
group_membership
(
r
.gr_mem
,
&
self
.username
));
}
self
.group_names
.insert
(
gid
,
group_name
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录