From c113f854a2c4fe35a7ad65335e058028bfc88eef Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 7 May 2020 02:30:43 -0700 Subject: [PATCH] Fix overlay.d on SAR again --- native/jni/init/rootdir.cpp | 4 ++-- native/jni/utils/files.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index 1a098a0d3..4db563ac7 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -316,8 +316,8 @@ void SARBase::patch_rootdir() { // Handle overlay.d load_overlay_rc(ROOTOVL); if (access(ROOTOVL "/sbin", F_OK) == 0) { - // Move files in overlay.d/sbin into Magisk's tmp_dir - mv_path(ROOTOVL "/sbin", tmp_dir); + // Move files in overlay.d/sbin into tmp_dir + mv_path(ROOTOVL "/sbin", "."); } // Patch init.rc diff --git a/native/jni/utils/files.cpp b/native/jni/utils/files.cpp index e6abc4300..62ceb607d 100644 --- a/native/jni/utils/files.cpp +++ b/native/jni/utils/files.cpp @@ -86,11 +86,13 @@ void frm_rf(int dirfd) { } void mv_path(const char *src, const char *dest) { - file_attr a; - getattr(src, &a); - if (S_ISDIR(a.st.st_mode)) { - xmkdirs(dest, 0); - setattr(dest, &a); + file_attr attr; + getattr(src, &attr); + if (S_ISDIR(attr.st.st_mode)) { + if (access(dest, F_OK) != 0) { + xmkdirs(dest, 0); + setattr(dest, &attr); + } mv_dir(xopen(src, O_RDONLY | O_CLOEXEC), xopen(dest, O_RDONLY | O_CLOEXEC)); } else{ xrename(src, dest); @@ -100,7 +102,7 @@ void mv_path(const char *src, const char *dest) { void mv_dir(int src, int dest) { auto dir = xopen_dir(src); - run_finally f([&]{ close(dest); }); + run_finally f([=]{ close(dest); }); for (dirent *entry; (entry = xreaddir(dir.get()));) { switch (entry->d_type) { case DT_DIR: