Skip to content

Commit

Permalink
Fix install as a user
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Jan 22, 2017
1 parent 5789f6e commit 517752a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libpkg/pkg_add.c
Expand Up @@ -1220,6 +1220,9 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
const char *path;
char buffer[128];
size_t link_len;
bool install_as_user;

install_as_user = (getenv("INSTALL_AS_USER") != NULL);

fromfd = open(src, O_DIRECTORY);
if (fromfd == -1) {
Expand All @@ -1241,7 +1244,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
}
d->uid = pwent.pw_uid;
} else {
d->uid = st.st_uid;
d->uid = install_as_user ? st.st_uid : 0;
}
if (d->gname[0] != '\0') {
if (getgrnam_r(d->gname, &grent, buffer, sizeof(buffer),
Expand Down Expand Up @@ -1286,7 +1289,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
}
f->uid = pwent.pw_uid;
} else {
f->uid = st.st_uid;
f->uid = install_as_user ? st.st_uid : 0;
}

if (f->gname[0] != '\0') {
Expand All @@ -1302,7 +1305,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)

if (f->perm == 0)
f->perm = st.st_mode & ~S_IFMT;
if (f->uid == 0)
if (f->uid == 0 && install_as_user)
f->uid = st.st_uid;
#ifdef HAVE_STRUCT_STAT_ST_MTIM
f->time[0] = st.st_atim;
Expand Down

0 comments on commit 517752a

Please sign in to comment.