aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bbot/worker/worker.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx
index d7a2570..1f5c946 100644
--- a/bbot/worker/worker.cxx
+++ b/bbot/worker/worker.cxx
@@ -2070,6 +2070,46 @@ build (size_t argc, const char* argv[])
rm.status |= r.status;
}
+
+ // Truncate logs if they would exceed the upload limit.
+ //
+ // @@ TMP: currently this limit is hard-coded. In the future it should be
+ // sent along with the task manifest.
+ //
+ const size_t upload_limit (10 * 1024 * 1024);
+ {
+ // Reserve 10K for other manifest values (alternatively, we could do it
+ // exactly in upload_manifest()).
+ //
+ const size_t manifest_size (10 * 1024);
+
+ size_t n (manifest_size);
+ for (const operation_result& r: rm.results)
+ n += r.log.size ();
+
+ if (n > upload_limit)
+ {
+ // Divide the size equally among all the operations and truncate any
+ // that exceed their allowance. This way we will get some information
+ // for each operation.
+ //
+ n = (upload_limit - manifest_size) / rm.results.size ();
+
+ for (operation_result& r: rm.results)
+ {
+ if (r.log.size () <= n)
+ continue;
+
+ // We need to be careful not to truncate it in the middle of UTF-8
+ // sequence. So we look for the last newline that still fits.
+ //
+ size_t p (n - 80 /* for the "log truncated" note */);
+ for (; p != 0 && r.log[p] != '\n'; --p) ;
+ r.log.resize (p != 0 ? p + 1 : 0); // Keep the newline.
+ r.log += "-------------------------------LOG TRUNCATED-------------------------------\n";
+ }
+ }
+ }
}
else
assert (rm.status == result_status::abort);