From: Jay Freeman (saurik) Date: Fri, 26 Aug 2016 05:06:33 +0000 (-0700) Subject: Chop bool Open() into void Open() and bool Look(). X-Git-Tag: v2.1.0~40 X-Git-Url: https://git.saurik.com/ldid.git/commitdiff_plain/878260fc4c6445c1c37f4051a0caa6ea0aac9f2f Chop bool Open() into void Open() and bool Look(). --- diff --git a/ldid.cpp b/ldid.cpp index 21e8863..91bf04c 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -1749,12 +1749,12 @@ 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, const void *flag) { + Open(access, fun([&](std::streambuf &data, const void *flag) { auto from(path + name); std::filebuf save; commit_[from] = Temporary(save, from); code(data, save); - })), "open(): %s", access.c_str()); + })); })); } } @@ -1766,14 +1766,15 @@ void DiskFolder::Save(const std::string &path, const void *flag, const Functor &code) { +bool DiskFolder::Look(const std::string &path) { + return _syscall(access(Path(path).c_str(), R_OK), ENOENT) == 0; +} + +void 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); + _assert_(result == &data, "DiskFolder::Open(%s)", path.c_str()); code(data, NULL); - return true; } void DiskFolder::Find(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link) { @@ -1791,7 +1792,11 @@ void SubFolder::Save(const std::string &path, const void *flag, const Functor &code) { +bool SubFolder::Look(const std::string &path) { + return parent_.Look(path_ + path); +} + +void SubFolder::Open(const std::string &path, const Functor &code) { return parent_.Open(path_ + path, code); } @@ -1826,7 +1831,14 @@ void UnionFolder::Save(const std::string &path, const void *flag, const Functor< return parent_.Save(Map(path), flag, code); } -bool UnionFolder::Open(const std::string &path, const Functor &code) { +bool UnionFolder::Look(const std::string &path) { + auto file(resets_.find(path)); + if (file != resets_.end()) + return true; + return parent_.Look(Map(path)); +} + +void UnionFolder::Open(const std::string &path, const Functor &code) { auto file(resets_.find(path)); if (file == resets_.end()) return parent_.Open(Map(path), code); @@ -1835,7 +1847,6 @@ bool UnionFolder::Open(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link) { @@ -1999,12 +2010,12 @@ 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, const void *flag) { + 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")); })); - })), "open(): Info.plist"); + })); static const std::string directory("_CodeSignature/"); static const std::string signature(directory + "CodeResources"); @@ -2014,12 +2025,6 @@ 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, const void *) { - plist_d(buffer, fun([&](plist_t node) { - // XXX: maybe attempt to preserve existing rules - })); - })); - if (true) { rules1.insert(Rule{1, NoMode, "^"}); rules1.insert(Rule{10000, OmitMode, "^(Frameworks/[^/]+\\.framework/|PlugIns/[^/]+\\.appex/|PlugIns/[^/]+\\.appex/Frameworks/[^/]+\\.framework/|())SC_Info/[^/]+\\.(sinf|supf|supp)$"}); diff --git a/ldid.hpp b/ldid.hpp index 3765c9f..55c50ea 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -50,7 +50,8 @@ FunctorImpl fun(const Function_ &value) { class Folder { public: 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 bool Look(const std::string &path) = 0; + virtual void Open(const std::string &path, const Functor &code) = 0; virtual void Find(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link) = 0; }; @@ -70,7 +71,8 @@ class DiskFolder : ~DiskFolder(); virtual void Save(const std::string &path, const void *flag, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual bool Look(const std::string &path); + virtual void Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link); }; @@ -85,7 +87,8 @@ class SubFolder : SubFolder(Folder &parent, const std::string &path); virtual void Save(const std::string &path, const void *flag, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual bool Look(const std::string &path); + virtual void Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link); }; @@ -119,7 +122,8 @@ class UnionFolder : UnionFolder(Folder &parent); virtual void Save(const std::string &path, const void *flag, const Functor &code); - virtual bool Open(const std::string &path, const Functor &code); + virtual bool Look(const std::string &path); + virtual void Open(const std::string &path, const Functor &code); virtual void Find(const std::string &path, const Functor &)> &)> &code, const Functor &)> &link); void operator ()(const std::string &from) {