]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Do tmp -> new using link() + unlink(). Use "new" way for unique filename
authorTimo Sirainen <tss@iki.fi>
Mon, 17 Feb 2003 20:45:02 +0000 (22:45 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 17 Feb 2003 20:45:02 +0000 (22:45 +0200)
generation.

--HG--
branch : HEAD

src/lib-storage/index/maildir/maildir-save.c

index d30874479cbf9deacf5b5abf582b8c3846cc8324..4c8130530444f649b4fe9f0f595c735817f5b086 100644 (file)
@@ -33,7 +33,7 @@ const char *maildir_generate_tmp_filename(void)
 
        hostpid_init();
 
-       return t_strdup_printf("%s.%s_%u.%s", dec2str(ioloop_time),
+       return t_strdup_printf("%s.P%sQ%u.%s", dec2str(ioloop_time),
                               my_pid, create_count++, my_hostname);
 }
 
@@ -97,29 +97,30 @@ static int maildir_copy(struct mail_save_context *ctx,
                        const char *src, const char *dest)
 {
        const char *tmp_path, *new_path;
+       int failed;
 
        t_push();
 
        tmp_path = t_strconcat(ctx->tmpdir, "/", src, NULL);
        new_path = t_strconcat(ctx->newdir, "/", dest, NULL);
 
-       if (rename(tmp_path, new_path) == 0) {
-               t_pop();
-               return TRUE;
-       }
-
-       if (errno == ENOSPC) {
-               mail_storage_set_error(ctx->ibox->box.storage,
-                                      "Not enough disk space");
-       } else {
-               mail_storage_set_critical(ctx->ibox->box.storage,
-                                         "rename(%s, %s) failed: %m",
-                                         tmp_path, new_path);
+       if (link(tmp_path, new_path) == 0)
+               failed = FALSE;
+       else {
+               failed = TRUE;
+               if (errno == ENOSPC) {
+                       mail_storage_set_error(ctx->ibox->box.storage,
+                                              "Not enough disk space");
+               } else {
+                       mail_storage_set_critical(ctx->ibox->box.storage,
+                                                 "link(%s, %s) failed: %m",
+                                                 tmp_path, new_path);
+               }
        }
 
        (void)unlink(tmp_path);
        t_pop();
-       return FALSE;
+       return !failed;
 }
 
 int maildir_storage_save_next(struct mail_save_context *ctx,