]> git.sur5r.net Git - openldap/commitdiff
Fix mdb_env_copy
authorHoward Chu <hyc@openldap.org>
Tue, 4 Dec 2012 14:30:22 +0000 (06:30 -0800)
committerHoward Chu <hyc@openldap.org>
Tue, 4 Dec 2012 14:30:22 +0000 (06:30 -0800)
Just write in 2^31 sized chunks

libraries/liblmdb/mdb.c

index 4af49989cde992de3f07f7307ebe0c8e933fedf7..d1f957bcd83df480b5e168444258f64adb16b518 100644 (file)
@@ -3533,22 +3533,34 @@ mdb_env_copy(MDB_env *env, const char *path)
 
        ptr = env->me_map + wsize;
        wsize = txn->mt_next_pgno * env->me_psize - wsize;
+#define MAX_WRITE      2147483648U
 #ifdef _WIN32
-#define MAX_UINT32     4294967295U
        while (wsize > 0) {
                DWORD len, w2;
-               if (wsize > MAX_UINT32)
-                       w2 = MAX_UINT32 - env->me_psize + 1;    /* write in pagesize chunks */
+               if (wsize > MAX_WRITE)
+                       w2 = MAX_WRITE;
                else
                        w2 = wsize;
                rc = WriteFile(newfd, ptr, w2, &len, NULL);
                rc = (len == w2) ? MDB_SUCCESS : ErrCode();
                if (rc) break;
                wsize -= w2;
+               ptr += w2;
        }
 #else
-       rc = write(newfd, ptr, wsize);
-       rc = (rc == (int)wsize) ? MDB_SUCCESS : ErrCode();
+       while (wsize > 0) {
+               size_t w2;
+               ssize_t wres;
+               if (wsize > MAX_WRITE)
+                       w2 = MAX_WRITE;
+               else
+                       w2 = wsize;
+               wres = write(newfd, ptr, w2);
+               rc = (wres > 0) ? MDB_SUCCESS : ErrCode();
+               if (rc) break;
+               wsize -= wres;
+               ptr += wres;
+       }
 #endif
        mdb_txn_abort(txn);