Skip to content

Commit

Permalink
Support user and group on Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed Feb 26, 2020
1 parent 28a07e0 commit 03ffdff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
8 changes: 6 additions & 2 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7735,6 +7735,7 @@ readdirex({directory} [, {expr}]) *readdirex()*

The Dictionary for file and directory information has the
following items:
group Group name of the entry. (Only on Unix)
name Name of the entry.
perm Permissions of the entry. See |getfperm()|.
size Size of the entry. See |getfsize()|.
Expand All @@ -7750,8 +7751,11 @@ readdirex({directory} [, {expr}]) *readdirex()*
Symlink to a dir "linkd"
Other symlink "link"
Other reparse point "reparse"
If the entry is a symlink, the Dictionary includes the
information of the symlink itself, not the target.
user User name of the entry's owner. (Only on Unix)
On Unix, if the entry is a symlink, the Dictionary includes
the information of the target (except the "type" item).
On MS-Windows, it includes the information of the symlink
itself because of performance reasons.

When {expr} is omitted all entries are included.
When {expr} is given, it is evaluated to check what to do:
Expand Down
40 changes: 35 additions & 5 deletions src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#if defined(__TANDEM) || defined(__MINT__)
# include <limits.h> // for SSIZE_MAX
#endif
#if defined(UNIX) && defined(FEAT_EVAL)
# include <pwd.h>
# include <grp.h>
#endif

// Is there any system that doesn't have access()?
#define USE_MCH_ACCESS
Expand Down Expand Up @@ -4508,6 +4512,11 @@ create_readdirex_item(WIN32_FIND_DATAW *wfd)
if (dict_add_string(item, "perm", getfpermwfd(wfd, permbuf)) == FAIL)
goto theend;

if (dict_add_string(item, "user", (char_u*)"") == FAIL)
goto theend;
if (dict_add_string(item, "group", (char_u*)"") == FAIL)
goto theend;

return item;

theend:
Expand All @@ -4525,7 +4534,9 @@ create_readdirex_item(char_u *path, char_u *name)
int ret, link = FALSE;
varnumber_T size;
char_u permbuf[] = "---------";
char_u *type;
char_u *q;
struct passwd *pw;
struct group *gr;

item = dict_alloc();
if (item == NULL)
Expand Down Expand Up @@ -4564,16 +4575,31 @@ create_readdirex_item(char_u *path, char_u *name)
if (link)
{
if (S_ISDIR(st.st_mode))
type = (char_u*)"linkd";
q = (char_u*)"linkd";
else
type = (char_u*)"link";
q = (char_u*)"link";
}
else
type = getftypest(&st);
if (dict_add_string(item, "type", type) == FAIL)
q = getftypest(&st);
if (dict_add_string(item, "type", q) == FAIL)
goto theend;
if (dict_add_string(item, "perm", getfpermst(&st, permbuf)) == FAIL)
goto theend;

pw = getpwuid(st.st_uid);
if (pw == NULL)
q = (char_u*)"";
else
q = (char_u*)pw->pw_name;
if (dict_add_string(item, "user", q) == FAIL)
goto theend;
gr = getgrgid(st.st_gid);
if (gr == NULL)
q = (char_u*)"";
else
q = (char_u*)gr->gr_name;
if (dict_add_string(item, "group", q) == FAIL)
goto theend;
}
else
{
Expand All @@ -4585,6 +4611,10 @@ create_readdirex_item(char_u *path, char_u *name)
goto theend;
if (dict_add_string(item, "perm", (char_u*)"") == FAIL)
goto theend;
if (dict_add_string(item, "user", (char_u*)"") == FAIL)
goto theend;
if (dict_add_string(item, "group", (char_u*)"") == FAIL)
goto theend;
}
return item;

Expand Down

0 comments on commit 03ffdff

Please sign in to comment.