4 #define deprint(...) /* eprint(__VA_ARGS__) */
9 if(strncmp(s, "/mail/fs/", 9) == 0)
10 if((s = strrchr(s, '/')) && strcmp(s + 1, "mbox") == 0)
22 isdir = d && d->mode & DMDIR;
28 docreate(char *file, int perm)
34 fd = create(file, OREAD, perm);
58 * if we can deliver to this mbox, it needs
59 * to be read/execable all the way down
73 if(docreate(s, DMDIR|mode) < 0)
81 copyfile(char *a, char *b, int flags)
84 int fd, fd1, mode, i, m, n, r;
91 fd1 = create(b, OWRITE|OEXCL, DMEXCL|mode);
92 if(fd == -1 || fd1 == -1){
99 while((n = read(fd, s, sizeof s)) > 0)
100 for(i = 0; i != n; i += m)
101 if((m = write(fd1, s + i, n - i)) == -1)
110 if((flags & Rtrunc) == 0)
117 if(d = dirfstat(fd)){
119 r = dirfwstat(fd, d);
126 copydir(char *a, char *b, int flags)
128 char *p, buf[Pathlen], ns[Pathlen], owd[Pathlen];
129 int fd, fd1, len, i, n, r;
133 fd1 = create(b, OWRITE|OEXCL, DMEXCL|0777);
135 if(fd == -1 || fd1 == -1){
142 if(d = dirfstat(fd)){
148 getwd(owd, sizeof owd);
152 p = seprint(buf, buf + sizeof buf, "%s/", b);
153 len = buf + sizeof buf - p;
154 n = dirreadall(fd, &d);
156 for(i = 0; i < n; i++){
157 snprint(p, len, "%s", d[i].name);
159 snprint(ns, sizeof ns, "%s/%s", a, d[i].name);
160 r |= copydir(ns, buf, 0);
163 r |= copyfile(d[i].name, buf, 0);
169 if((flags & Rtrunc) == 0)
177 rename(char *a, char *b, int flags)
183 e0 = strrchr(a, '/');
184 e1 = strrchr(b, '/');
185 if(!e0 || !e1 || !e1[1])
189 if(strncmp(a, b, e0 - a) == 0)
190 if(!delivery(a) || isdir(a)){
192 if(!(d = dirfstat(fd))){
197 r = dirfwstat(fd, d);
198 deprint("rename %s %s -> %d\n", a, b, r);
199 if(r != -1 && flags & Rtrunc)
200 close(create(a, OWRITE, d->mode));
209 return copydir(a, b, flags);
210 return copyfile(a, b, flags);
214 localrename(Mailbox *mb, char *p2, int flags)
218 static char err[2*Pathlen];
224 deprint("localrename %s: %s %s\n", msg, path, p2);
226 r = rename(path, p2, flags);
228 snprint(err, sizeof err, "%s: can't %s\n", path, msg);
229 deprint("localrename %s\n", err);