]> mj.ucw.cz Git - eval.git/commitdiff
Keep history of submitted tasks.
authorMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 19:37:21 +0000 (21:37 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 19:37:21 +0000 (21:37 +0200)
TODO
bin/mo-create-submit
submit/config
submit/submitd.c
submit/submitd.h
submit/tasks.c

diff --git a/TODO b/TODO
index 2977d02081867d519871d9a3ad4250bf6e4d7bce..6364c45283f1a6e0e1f1fb252c2343eac86762ce 100644 (file)
--- a/TODO
+++ b/TODO
@@ -18,7 +18,6 @@ Installer:
 
 New submitter:
 - Checking of contest time (and per-contestant exceptions)
-- Keeping history and pruning status files
 - Remember hashes
 - contest: override failed check
 - contest: local history
index 573d658423b06a312c9c0530436b2cbfb388880b..fe0434d731679f4ed9868f1a2c4c2413fa016d09 100755 (executable)
@@ -29,6 +29,6 @@ cp -a $H/submit/lib lib
 rm -rf tmp
 mkdir -p tmp
 
-mkdir -p log
+mkdir -p log history
 
 chown -R $REMOTE_SUBMIT_USER.$REMOTE_SUBMIT_GROUP $MO_ROOT/eval/submit
index 9cf54f204c9cee25ac7717e8ec2c9681d96e1b87..1b00f46b005afa1d932f87cb1874a49a1c2c7a2e 100644 (file)
@@ -31,6 +31,10 @@ CACert                       certs/ca-cert.pem
 ServerCert             certs/server-cert.pem
 ServerKey              certs/server-key.pem
 
+# Keep history of all submitted files in files of a given name prefix
+# (formatted by strftime; default: no history kept)
+History                        history/%H%M%S-
+
 # Rules for accepting connections (first matching rule is used)
 Access {
        # IP address ranges matched by this rule
@@ -68,9 +72,9 @@ Tasks {
 #      Task plans
        Task { Name world; OpenData 10; MaxSize 1M; }
 
-       Task            necklace
-       Task            nei
-       Task            town
+       Task            asteroids
+       Task            cards
+       Task            lines
 
        Extension       c cpp pas
        OpenDataExt     out
index 4c1415b48d08d44aa31bdebbee9116a26d3c9d97..9160cf91765ae1459039b02d9fe73ab229381f2c 100644 (file)
@@ -33,6 +33,7 @@ static uns session_timeout;
 static byte *ca_cert_name = "?";
 static byte *server_cert_name = "?";
 static byte *server_key_name = "?";
+byte *history_format;
 static clist access_rules;
 static uns trace_tls;
 uns max_request_size;
@@ -70,6 +71,7 @@ static struct cf_section submitd_conf = {
     CF_STRING("CACert", &ca_cert_name),
     CF_STRING("ServerCert", &server_cert_name),
     CF_STRING("ServerKey", &server_key_name),
+    CF_STRING("History", &history_format),
     CF_LIST("Access", &access_rules, &access_conf),
     CF_UNS("TraceTLS", &trace_tls),
     CF_UNS("TraceCommands", &trace_commands),
index 5d5eea276a4b08b9818dd4149ecd1d87ff59086e..42a8e539e32271404debcb2c8ec878c491839364 100644 (file)
@@ -50,6 +50,7 @@ struct conn {
 };
 
 extern uns max_request_size, max_attachment_size, trace_commands;
+extern byte *history_format;
 
 /* submitd.c */
 
index 00df760f0882bbb76d1d6a55fd9d08cbf49b942a..243cd907f0ee32c0adf12d1a56172125bc0ab014 100644 (file)
@@ -16,6 +16,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <time.h>
 
 #include "submitd.h"
 
@@ -193,7 +194,29 @@ task_status_find_part(struct odes *to, byte *part, uns create)
   return o;
 }
 
-void task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version UNUSED, struct fastbuf *fb)
+static void task_record_history(byte *user, byte *task, byte *part, byte *ext, uns version, byte *submitted_name)
+{
+  if (!history_format)
+    return;
+
+  time_t now = time(NULL);
+  struct tm *tm = localtime(&now);
+  byte prefix[256];
+  if (strftime(prefix, sizeof(prefix), history_format, tm) <= 0)
+    {
+      msg(L_ERROR, "Error formatting history prefix: too long");
+      return;
+    }
+
+  byte *name = stk_printf("%s%s:%s:%s:v%d.%s", prefix, user, task, (strcmp(task, part) ? part : (byte*)""), version, ext);
+  struct fastbuf *orig = bopen(submitted_name, O_RDONLY, 4096);
+  struct fastbuf *hist = bopen(name, O_WRONLY | O_CREAT | O_EXCL, 4096);
+  bbcopy_slow(orig, hist, ~0U);
+  bclose(hist);
+  bclose(orig);
+}
+
+void task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version, struct fastbuf *fb)
 {
   byte *dir = stk_printf("solutions/%s/%s", user, task);
   byte *name = stk_printf("%s/%s.%s", dir, part, ext);
@@ -205,6 +228,8 @@ void task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version
   bconfig(fb, BCONFIG_IS_TEMP_FILE, 0);
   if (rename(fb->name, name) < 0)
     die("Cannot rename %s to %s: %m", fb->name, name);
+
+  task_record_history(user, task, part, ext, version, name);
 }
 
 void task_delete_part(byte *user, byte *task, byte *part, byte *ext, uns version UNUSED)