X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=submit%2Ftasks.c;h=f0e933381f405ffa546be4462c7112d4711f0a49;hb=11186a847caaa8904ecd26f65d5fdc5bcdb2096a;hp=675f4d8a471f5d5f95b6954abd1e3addcabe3da0;hpb=6324cb417d421274a384cfae916b039cbe56d6e0;p=eval.git diff --git a/submit/tasks.c b/submit/tasks.c index 675f4d8..f0e9333 100644 --- a/submit/tasks.c +++ b/submit/tasks.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "submitd.h" @@ -33,7 +34,7 @@ tasks_conf_commit(void *p UNUSED) if (t->open_data) { for (uns i=1; i<=t->open_data; i++) - simp_append(cf_pool, &t->parts)->s = mp_printf(cf_pool, "%d", i); + simp_append(cf_pool, &t->parts)->s = mp_printf(cf_pool, "%02d", i); t->extensions = &open_data_extensions; } else @@ -50,6 +51,7 @@ static struct cf_section task_conf = { CF_ITEMS { CF_STRING("Name", PTR_TO(struct task, name)), CF_UNS("OpenData", PTR_TO(struct task, open_data)), + CF_UNS("MaxSize", PTR_TO(struct task, max_size)), CF_END } }; @@ -192,7 +194,31 @@ 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); @@ -204,9 +230,12 @@ 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) +void +task_delete_part(byte *user, byte *task, byte *part, byte *ext, uns version UNUSED) { byte *dir = stk_printf("solutions/%s/%s", user, task); byte *name = stk_printf("%s/%s.%s", dir, part, ext);