From: Martin Mares Date: Thu, 28 Jun 2007 19:37:21 +0000 (+0200) Subject: Keep history of submitted tasks. X-Git-Tag: python-dummy-working~332 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=72a103ad409049185dba69f935e69d7a04b6db24;p=eval.git Keep history of submitted tasks. --- diff --git a/TODO b/TODO index 2977d02..6364c45 100644 --- 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 diff --git a/bin/mo-create-submit b/bin/mo-create-submit index 573d658..fe0434d 100755 --- a/bin/mo-create-submit +++ b/bin/mo-create-submit @@ -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 diff --git a/submit/config b/submit/config index 9cf54f2..1b00f46 100644 --- a/submit/config +++ b/submit/config @@ -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 diff --git a/submit/submitd.c b/submit/submitd.c index 4c1415b..9160cf9 100644 --- a/submit/submitd.c +++ b/submit/submitd.c @@ -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), diff --git a/submit/submitd.h b/submit/submitd.h index 5d5eea2..42a8e53 100644 --- a/submit/submitd.h +++ b/submit/submitd.h @@ -50,6 +50,7 @@ struct conn { }; extern uns max_request_size, max_attachment_size, trace_commands; +extern byte *history_format; /* submitd.c */ diff --git a/submit/tasks.c b/submit/tasks.c index 00df760..243cd90 100644 --- a/submit/tasks.c +++ b/submit/tasks.c @@ -16,6 +16,7 @@ #include #include #include +#include #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)