ref: 567dc43094a9a507f605d55cfb629bb49af856b9
parent: a895be69922ed23ff37f898a714374d03de02187
author: sirjofri <sirjofri@sirjofri.de>
date: Thu Jun 20 17:34:32 EDT 2024
adds rename support (rename-mv changes title), adds mv support (create file with shortname in new status directory)
--- a/todofs.c
+++ b/todofs.c
@@ -322,13 +322,45 @@
if (t->title)
free(t->title);
free(t->dir);
+
+ t->cassignee = 0;
+ t->cgroup = 0;
+ t->cfname = 0;
+ t->title = nil;
+ t->dir = nil;
}
static int
+settasktitle(Task *t, char *title)
+{
+ char buf[64], *c;
+
+ if (t->title)
+ free(t->title);
+
+ if (t->cfname && t->dir->name)
+ free(t->dir->name);
+
+ if (title && title[0]) {
+ t->title = strdup(title);
+
+ snprint(buf, sizeof(buf), "%s", title);
+ for (c = buf; *c; c++) {
+ if (*c == ' ' || *c == '\t')
+ *c = '_';
+ }
+ t->dir->name = smprint("%s-%s", t->hash, buf);
+ } else {
+ t->dir->name = strdup(t->hash);
+ }
+ t->cfname = 1;
+ return 1;
+}
+
+static int
updatetask(Task *t, char *name, char *assignee, char *group, char *title)
{
char path[256];
- char *c, buf[64];
snprint(path, sizeof(path), "%s/%s", srcdir, name);
snprint(t->hash, sizeof(t->hash), "%s", name);
@@ -335,9 +367,6 @@
freetask(t);
- if (title) {
- t->title = strdup(title);
- }
t->dir = dirstat(path);
if (assignee) {
t->dir->uid = strdup(assignee);
@@ -348,21 +377,7 @@
t->cgroup = 1;
}
- if (title) {
- snprint(buf, sizeof(buf), "%s", title);
-
- for (c = buf; *c; c++) {
- if (*c == ' ' || *c == '\t') {
- *c = '_';
- }
- }
-
- t->dir->name = smprint("%s-%s", t->hash, buf);
- } else
- t->dir->name = strdup(t->hash);
-
- t->cfname = 1;
- return 1;
+ return settasktitle(t, title);
}
int
@@ -699,9 +714,70 @@
}
}
+int
+taskmv(Task *t, Status *from, Status *to)
+{
+ Task *prev;
+
+ if (from->tasks == t) {
+ from->tasks = t->next;
+ goto Chain;
+ }
+
+ for (prev = from->tasks; prev->next && prev->next != t; prev = prev->next)
+ ;
+
+ prev->next = t->next;
+
+Chain:
+ t->next = nil;
+ if (!to->tasks) {
+ to->tasks = t;
+ return 1;
+ }
+ for (prev = to->tasks; prev->next; prev = prev->next)
+ ;
+ prev->next = t;
+ return 1;
+}
+
void
fscreate(Req *r)
{
+ Status *s;
+ Task *t;
+ int tid, sid;
+
+ switch (qidtype(r->fid->qid.path)) {
+ case Qstatus:
+ s = getnstatus(qidnum(r->fid->qid.path));
+ if (!s) {
+ respond(r, "status not found");
+ return;
+ }
+ t = getstask(r->ifcall.name, &sid, &tid);
+ if (t) {
+ if (sid == qidnum(r->fid->qid.path)) {
+ respond(r, "task already has status");
+ return;
+ }
+ if (!taskmv(t, getnstatus(sid), s)) {
+ responderror(r);
+ return;
+ }
+ r->fid->qid = (Qid){mkqid(Qtask, t->id), 0, 0};
+ r->ofcall.qid = r->fid->qid;
+ } else {
+ // TODO: create new task
+ respond(r, "not implemented yet");
+ return;
+ }
+ savedata();
+ break;
+ default:
+ respond(r, "not allowed");
+ return;
+ }
respond(r, nil);
}
@@ -786,6 +862,10 @@
free(t->dir->gid);
t->dir->gid = strdup(r->d.gid);
t->cgroup = 1;
+ save++;
+ }
+ if (r->d.name && r->d.name[0]) {
+ settasktitle(t, r->d.name);
save++;
}