1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2024-10-27 20:34:20 +00:00

Allow subdirs in artifacts directory

Extend populateArtifacts() with a subdir parameter (default initialized to ".")
to allow for recursive calls. With subdirs encountered, call recursively.
This commit is contained in:
Jan-Benedict Glaw 2021-03-07 10:48:49 +01:00 committed by Oliver Giles
parent 9b8c3762ec
commit 7e77ec1211
2 changed files with 12 additions and 9 deletions

View File

@ -203,18 +203,21 @@ std::list<std::string> Laminar::listKnownJobs() {
return res; return res;
} }
void Laminar::populateArtifacts(Json &j, std::string job, uint num) const { void Laminar::populateArtifacts(Json &j, std::string job, uint num, kj::Path subdir) const {
kj::Path runArchive{job,std::to_string(num)}; kj::Path runArchive{job,std::to_string(num)};
runArchive = runArchive.append(subdir);
KJ_IF_MAYBE(dir, fsHome->tryOpenSubdir("archive"/runArchive)) { KJ_IF_MAYBE(dir, fsHome->tryOpenSubdir("archive"/runArchive)) {
for(kj::StringPtr file : (*dir)->listNames()) { for(kj::StringPtr file : (*dir)->listNames()) {
kj::FsNode::Metadata meta = (*dir)->lstat(kj::Path{file}); kj::FsNode::Metadata meta = (*dir)->lstat(kj::Path{file});
if(meta.type != kj::FsNode::Type::FILE) if(meta.type == kj::FsNode::Type::FILE) {
continue; j.StartObject();
j.StartObject(); j.set("url", archiveUrl + (runArchive/file).toString().cStr());
j.set("url", archiveUrl + (runArchive/file).toString().cStr()); j.set("filename", (subdir/file).toString().cStr());
j.set("filename", file.cStr()); j.set("size", meta.size);
j.set("size", meta.size); j.EndObject();
j.EndObject(); } else if(meta.type == kj::FsNode::Type::DIRECTORY) {
populateArtifacts(j, job, num, subdir/file);
}
} }
} }
} }

View File

@ -104,7 +104,7 @@ private:
bool tryStartRun(std::shared_ptr<Run> run, int queueIndex); bool tryStartRun(std::shared_ptr<Run> run, int queueIndex);
void handleRunFinished(Run*); void handleRunFinished(Run*);
// expects that Json has started an array // expects that Json has started an array
void populateArtifacts(Json& out, std::string job, uint num) const; void populateArtifacts(Json& out, std::string job, uint num, kj::Path subdir = kj::Path::parse(".")) const;
Run* activeRun(const std::string name, uint num) { Run* activeRun(const std::string name, uint num) {
auto it = activeJobs.byNameNumber().find(boost::make_tuple(name, num)); auto it = activeJobs.byNameNumber().find(boost::make_tuple(name, num));