@@ -71,19 +71,19 @@ std::unique_ptr<Fifo> Fifo::New(kj::Promise<T>&& p) {
7171namespace {
7272class FileProvider : public capnproto ::FileSender::Server {
7373 public:
74- explicit FileProvider (
75- std::unordered_map<util::SHA256_t, std::string, util::SHA256_t::Hasher>
76- known_files)
74+ explicit FileProvider (std::unordered_map<util::SHA256_t, util::FileWrapper,
75+ util::SHA256_t::Hasher>
76+ known_files)
7777 : known_files_(std::move(known_files)) {}
7878
7979 kj::Promise<void > requestFile (RequestFileContext context) override {
80- std::string path = known_files_.at (context.getParams ().getHash ());
81- return util::File::HandleRequestFile (path ,
80+ util::FileWrapper *file = & known_files_.at (context.getParams ().getHash ());
81+ return util::File::HandleRequestFile (file ,
8282 context.getParams ().getReceiver ());
8383 }
8484
8585 private:
86- std::unordered_map<util::SHA256_t, std::string , util::SHA256_t::Hasher>
86+ std::unordered_map<util::SHA256_t, util::FileWrapper , util::SHA256_t::Hasher>
8787 known_files_;
8888};
8989
@@ -159,7 +159,24 @@ File* Frontend::provideFile(const std::string& path,
159159 bool is_executable) {
160160 auto req = frontend_context_.provideFileRequest ();
161161 util::SHA256_t hash = util::File::Hash (path);
162- known_files_.emplace (hash, path);
162+ known_files_.emplace (hash, util::FileWrapper::FromPath (path));
163+ hash.ToCapnp (req.initHash ());
164+ req.setDescription (description);
165+ req.setIsExecutable (is_executable);
166+ files_.push_back (File::New (req.send (), this , is_executable));
167+ return files_.back ().get ();
168+ }
169+
170+ File *Frontend::provideFileContent (const std::string &content,
171+ const std::string &description,
172+ bool is_executable) {
173+ auto req = frontend_context_.provideFileRequest ();
174+ util::SHA256 hasher;
175+ // NOLINTNEXTLINE
176+ hasher.update (reinterpret_cast <const unsigned char *>(&content[0 ]),
177+ content.size ());
178+ util::SHA256_t hash = hasher.finalize ();
179+ known_files_.emplace (hash, util::FileWrapper::FromContent (content));
163180 hash.ToCapnp (req.initHash ());
164181 req.setDescription (description);
165182 req.setIsExecutable (is_executable);
@@ -188,7 +205,7 @@ ExecutionGroup* Frontend::addExecutionGroup(const std::string& description) {
188205void Frontend::evaluate () {
189206 finish_builder_.AddPromise (std::move (builder_).Finalize ().then ([this ]() {
190207 auto req = frontend_context_.startEvaluationRequest ();
191- req.setSender (kj::heap<FileProvider>(known_files_));
208+ req.setSender (kj::heap<FileProvider>(std::move ( known_files_) ));
192209 return req.send ().ignoreResult ();
193210 }),
194211 " Evaluate" );
0 commit comments