From ecfa4aafc1573c2d3c246e5ab9b76c878eb6f5a3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 26 Aug 2017 23:19:56 +0800 Subject: [PATCH] Fix clone_attr --- jni/utils/misc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/jni/utils/misc.c b/jni/utils/misc.c index c0af9d58e..a9dd695e2 100644 --- a/jni/utils/misc.c +++ b/jni/utils/misc.c @@ -379,12 +379,14 @@ int cp_afc(const char *source, const char *target) { } void clone_attr(const char *source, const char *target) { - int sourcefd, targetfd; - sourcefd = xopen(source, O_RDONLY); - targetfd = xopen(target, O_RDONLY); - fclone_attr(sourcefd, targetfd); - close(sourcefd); - close(targetfd); + struct stat buf; + lstat(target, &buf); + chmod(target, buf.st_mode & 0777); + chown(target, buf.st_uid, buf.st_gid); + char *con; + lgetfilecon(source, &con); + lsetfilecon(target, con); + free(con); } void fclone_attr(const int sourcefd, const int targetfd) {