summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbig biff <bigbiff@teamw.in>2019-01-19 17:02:53 +0100
committerGerrit Code Review <gerrit2@gerrit.omnirom.org>2019-01-19 17:02:53 +0100
commitc757a6647764a4cf5b308a353c09c2bc38733589 (patch)
treed4a65909dfa5b5ba4dcfb6bc41254e4f91e5e575
parenttoybox: create getprop symlink on SDK 27 (diff)
parentRevert "updater: Remove dead make_parents()." (diff)
downloadandroid_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar.gz
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar.bz2
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar.lz
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar.xz
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.tar.zst
android_bootable_recovery-c757a6647764a4cf5b308a353c09c2bc38733589.zip
Diffstat (limited to '')
-rw-r--r--updater/install.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index 741d97014..2266127f2 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -97,6 +97,34 @@ static void uiPrint(State* state, const std::string& buffer) {
LOG(INFO) << buffer;
}
+static bool is_dir(const std::string& dirpath) {
+ struct stat st;
+ return stat(dirpath.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
+}
+
+// Create all parent directories of name, if necessary.
+static bool make_parents(const std::string& name) {
+ size_t prev_end = 0;
+ while (prev_end < name.size()) {
+ size_t next_end = name.find('/', prev_end + 1);
+ if (next_end == std::string::npos) {
+ break;
+ }
+ std::string dir_path = name.substr(0, next_end);
+ if (!is_dir(dir_path)) {
+ int result = mkdir(dir_path.c_str(), 0700);
+ if (result != 0) {
+ PLOG(ERROR) << "failed to mkdir " << dir_path << " when make parents for " << name;
+ return false;
+ }
+
+ LOG(INFO) << "created [" << dir_path << "]";
+ }
+ prev_end = next_end;
+ }
+ return true;
+}
+
void uiPrintf(State* _Nonnull state, const char* _Nonnull format, ...) {
std::string error_msg;