Attempt to set the proper uid/gid/contexts on new files and dirs
Files and folders that we create during backups, copy log, or MTP
operations often do not have the proper uid/gid/contexts assigned.
We will attempt to read the proper contexts from the settings
storage path and assign those same contexts to any files or dirs
that we create.
Change-Id: I769f9479854122b49b499de2175e6e2d026f8afd
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 9611424..b51024c 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -54,6 +54,7 @@
extern "C" {
#include "libcrecovery/common.h"
+ #include "set_metadata.h"
}
/* Execute a command */
@@ -406,9 +407,13 @@
while (pos != string::npos)
{
wholePath = pathCpy.substr(0, pos);
- if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST) {
- LOGERR("Unable to create folder: %s (errno=%d)\n", wholePath.c_str(), errno);
- return false;
+ if (!TWFunc::Path_Exists(wholePath)) {
+ if (mkdir(wholePath.c_str(), 0777)) {
+ LOGERR("Unable to create folder: %s (errno=%d)\n", wholePath.c_str(), errno);
+ return false;
+ } else {
+ tw_set_default_metadata(wholePath.c_str());
+ }
}
pos = pathCpy.find("/", pos + 1);