From: Jay Freeman (saurik) Date: Fri, 29 Jul 2016 12:57:28 +0000 (-0700) Subject: Provide a way to maintain file permissions in IPA. X-Git-Tag: v2.1.0~50 X-Git-Url: https://git.saurik.com/ldid.git/commitdiff_plain/fefcecb0b3ef4c15a074c0824cbbcb072f1b9a5a Provide a way to maintain file permissions in IPA. --- diff --git a/ldid.cpp b/ldid.cpp index 02e2675..a33cb55 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -1679,7 +1679,7 @@ void DiskFolder::Find(const std::string &root, const std::string &base, const Fu else code(base + name, fun([&](const Functor &code) { std::string access(root + base + name); - _assert_(Open(access, fun([&](std::streambuf &data) { + _assert_(Open(access, fun([&](std::streambuf &data, const void *flag) { NullBuffer save; code(data, save); })), "open(): %s", access.c_str()); @@ -1687,20 +1687,20 @@ void DiskFolder::Find(const std::string &root, const std::string &base, const Fu } } -void DiskFolder::Save(const std::string &path, const Functor &code) { +void DiskFolder::Save(const std::string &path, const void *flag, const Functor &code) { std::filebuf save; auto from(Path(path)); commit_[from] = Temporary(save, from); code(save); } -bool DiskFolder::Open(const std::string &path, const Functor &code) { +bool DiskFolder::Open(const std::string &path, const Functor &code) { std::filebuf data; auto result(data.open(Path(path).c_str(), std::ios::binary | std::ios::in)); if (result == NULL) return false; _assert(result == &data); - code(data); + code(data, NULL); return true; } @@ -1715,11 +1715,11 @@ SubFolder::SubFolder(Folder &parent, const std::string &path) : { } -void SubFolder::Save(const std::string &path, const Functor &code) { - return parent_.Save(path_ + path, code); +void SubFolder::Save(const std::string &path, const void *flag, const Functor &code) { + return parent_.Save(path_ + path, flag, code); } -bool SubFolder::Open(const std::string &path, const Functor &code) { +bool SubFolder::Open(const std::string &path, const Functor &code) { return parent_.Open(path_ + path, code); } @@ -1734,11 +1734,13 @@ std::string UnionFolder::Map(const std::string &path) { return remap->second; } -void UnionFolder::Map(const std::string &path, const Functor &)> &)> &code, const std::string &file, const Functor &)> &save) { +void UnionFolder::Map(const std::string &path, const Functor &)> &)> &code, const std::string &file, const Functor &)> &save) { if (file.size() >= path.size() && file.substr(0, path.size()) == path) code(file.substr(path.size()), fun([&](const Functor &code) { - parent_.Save(file, fun([&](std::streambuf &data) { - save(data, code); + save(fun([&](std::streambuf &data, const void *flag) { + parent_.Save(file, flag, fun([&](std::streambuf &save) { + code(data, save); + })); })); })); } @@ -1748,18 +1750,19 @@ UnionFolder::UnionFolder(Folder &parent) : { } -void UnionFolder::Save(const std::string &path, const Functor &code) { - return parent_.Save(Map(path), code); +void UnionFolder::Save(const std::string &path, const void *flag, const Functor &code) { + return parent_.Save(Map(path), flag, code); } -bool UnionFolder::Open(const std::string &path, const Functor &code) { +bool UnionFolder::Open(const std::string &path, const Functor &code) { auto file(resets_.find(path)); if (file == resets_.end()) return parent_.Open(Map(path), code); + auto &entry(file->second); - auto &data(file->second); + auto &data(entry.first); data.pubseekpos(0, std::ios::in); - code(data); + code(data, entry.second); return true; } @@ -1770,15 +1773,16 @@ void UnionFolder::Find(const std::string &path, const Functor &code) { - reset.second.pubseekpos(0, std::ios::in); - code(reset.second, save); + Map(path, code, reset.first, fun([&](const Functor &code) { + auto &entry(reset.second); + entry.first.pubseekpos(0, std::ios::in); + code(entry.first, entry.second); })); for (auto &remap : remaps_) - Map(path, code, remap.first, fun([&](std::streambuf &save, const Functor &code) { - parent_.Open(remap.second, fun([&](std::streambuf &data) { - code(data, save); + Map(path, code, remap.first, fun([&](const Functor &code) { + parent_.Open(remap.second, fun([&](std::streambuf &data, const void *flag) { + code(data, flag); })); })); } @@ -1919,7 +1923,7 @@ std::string Bundle(const std::string &root, Folder &folder, const std::string &k static const std::string info("Info.plist"); - _assert_(folder.Open(info, fun([&](std::streambuf &buffer) { + _assert_(folder.Open(info, fun([&](std::streambuf &buffer, const void *flag) { plist_d(buffer, fun([&](plist_t node) { executable = plist_s(plist_dict_get_item(node, "CFBundleExecutable")); identifier = plist_s(plist_dict_get_item(node, "CFBundleIdentifier")); @@ -1934,7 +1938,7 @@ std::string Bundle(const std::string &root, Folder &folder, const std::string &k auto &rules1(versions[""]); auto &rules2(versions["2"]); - folder.Open(signature, fun([&](std::streambuf &buffer) { + folder.Open(signature, fun([&](std::streambuf &buffer, const void *) { plist_d(buffer, fun([&](plist_t node) { // XXX: maybe attempt to preserve existing rules })); @@ -2066,7 +2070,7 @@ std::string Bundle(const std::string &root, Folder &folder, const std::string &k } } - folder.Save(signature, fun([&](std::streambuf &save) { + folder.Save(signature, NULL, fun([&](std::streambuf &save) { HashProxy proxy(local[signature], save); char *xml(NULL); uint32_t size; @@ -2075,8 +2079,8 @@ std::string Bundle(const std::string &root, Folder &folder, const std::string &k put(proxy, xml, size); })); - folder.Open(executable, fun([&](std::streambuf &buffer) { - folder.Save(executable, fun([&](std::streambuf &save) { + folder.Open(executable, fun([&](std::streambuf &buffer, const void *flag) { + folder.Save(executable, flag, fun([&](std::streambuf &save) { Slots slots; slots[1] = local.at(info); slots[3] = local.at(signature); diff --git a/ldid.hpp b/ldid.hpp index 5b2efda..6982e39 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -49,8 +49,8 @@ FunctorImpl fun(const Function_ &value) { class Folder { public: - virtual void Save(const std::string &path, const Functor &code) = 0; - virtual bool Open(const std::string &path, const Functor &code) = 0; + virtual void Save(const std::string &path, const void *flag, const Functor &code) = 0; + virtual bool Open(const std::string &path, const Functor &code) = 0; virtual void Find(const std::string &path, const Functor &)> &)> &code) = 0; }; @@ -69,8 +69,8 @@ class DiskFolder : DiskFolder(const std::string &path); ~DiskFolder(); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual void Save(const std::string &path, const void *flag, const Functor &code); + virtual bool Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code); }; @@ -84,8 +84,8 @@ class SubFolder : public: SubFolder(Folder &parent, const std::string &path); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual void Save(const std::string &path, const void *flag, const Functor &code); + virtual bool Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code); }; @@ -110,16 +110,16 @@ class UnionFolder : std::set deletes_; std::map remaps_; - std::map resets_; + std::map> resets_; std::string Map(const std::string &path); - void Map(const std::string &path, const Functor &)> &)> &code, const std::string &file, const Functor &)> &save); + void Map(const std::string &path, const Functor &)> &)> &code, const std::string &file, const Functor &)> &save); public: UnionFolder(Folder &parent); - virtual void Save(const std::string &path, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual void Save(const std::string &path, const void *flag, const Functor &code); + virtual bool Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code); void operator ()(const std::string &from) { @@ -131,9 +131,11 @@ class UnionFolder : remaps_[to] = from; } - std::stringbuf &operator [](const std::string &path) { - operator ()(path); - return resets_[path]; + std::stringbuf &operator ()(const std::string &from, const void *flag) { + operator ()(from); + auto &reset(resets_[from]); + reset.second = flag; + return reset.first; } };