Skip to content

Commit 4662568

Browse files
committed
chflags: adapt chflags handling to the recent changes
if the file is extracted in a temporary directory set the chflag as early as possible if not set it as before
1 parent c82baac commit 4662568

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

libpkg/pkg_add.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ get_gid_from_archive(struct archive_entry *ae)
188188
return (grent.gr_gid);
189189
}
190190

191+
static int
192+
set_chflags(int fd, const char *path, u_long fflags)
193+
{
194+
#ifdef HAVE_CHFLAGSAT
195+
if (getenv("INSTALL_AS_USER"))
196+
return (EPKG_OK);
197+
if (fflags == 0)
198+
return (EPKG_OK);
199+
if (chflagsat(fd, RELATIVE_PATH(path), fflags, AT_SYMLINK_NOFOLLOW) == -1) {
200+
pkg_fatal_errno("Fail to chflags %s", path);
201+
}
202+
#endif
203+
return (EPKG_OK);
204+
}
191205
int
192206
set_attrsat(int fd, const char *path, mode_t perm, uid_t uid, gid_t gid,
193207
const struct timespec *ats, const struct timespec *mts)
@@ -428,6 +442,9 @@ create_symlinks(struct pkg *pkg, struct pkg_file *f, const char *target, tempdir
428442
&f->time[0], &f->time[1]) != EPKG_OK) {
429443
return (EPKG_FATAL);
430444
}
445+
if (tmpdir != NULL)
446+
set_chflags(fd, path, f->fflags);
447+
431448
return (EPKG_OK);
432449
}
433450

@@ -651,6 +668,8 @@ create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,
651668
if (set_attrsat(fd, path, f->perm, f->uid, f->gid,
652669
&f->time[0], &f->time[1]) != EPKG_OK)
653670
return (EPKG_FATAL);
671+
if (tmpdir != NULL)
672+
set_chflags(fd, path, f->fflags);
654673

655674
return (EPKG_OK);
656675
}
@@ -861,14 +880,8 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)
861880
f->temppath, fto);
862881
}
863882

864-
#ifdef HAVE_CHFLAGSAT
865-
if (!install_as_user && f->fflags != 0) {
866-
if (chflagsat(pkg->rootfd, RELATIVE_PATH(fto),
867-
f->fflags, AT_SYMLINK_NOFOLLOW) == -1) {
868-
pkg_fatal_errno("Fail to chflags %s", fto);
869-
}
870-
}
871-
#endif
883+
if (set_chflags(pkg->rootfd, fto, f->fflags) != EPKG_OK)
884+
return (EPKG_FATAL);
872885
}
873886

874887
while (pkg_dirs(pkg, &d) == EPKG_OK) {
@@ -878,6 +891,8 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)
878891
if (set_attrsat(pkg->rootfd, d->path, d->perm,
879892
d->uid, d->gid, &d->time[0], &d->time[1]) != EPKG_OK)
880893
return (EPKG_FATAL);
894+
if (set_chflags(pkg->rootfd, d->path, d->fflags) != EPKG_OK)
895+
return (EPKG_FATAL);
881896
}
882897
if (tempdirs != NULL)
883898
tll_free(*tempdirs);

0 commit comments

Comments
 (0)