From: Salvador Ortiz Date: Thu, 5 Sep 2013 22:36:52 +0000 (-0500) Subject: ITS#7682 In mdb_env_copy retry open if O_DIRECT fails X-Git-Tag: OPENLDAP_REL_ENG_2_4_37~39^2~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cfc13e2b4837f5cde8433251357ca82686e5b709;p=openldap ITS#7682 In mdb_env_copy retry open if O_DIRECT fails --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 16db71ecde..9c5e7389de 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -4246,11 +4246,15 @@ mdb_env_copy(MDB_env *env, const char *path) newfd = CreateFile(lpath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL); #else - newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL #ifdef O_DIRECT - |O_DIRECT + /* The OS supports O_DIRECT, try with it */ + newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL|O_DIRECT, 0666); + /* But open can fail if O_DIRECT isn't supported by the file system + * so retry without the flag + */ + if (newfd == INVALID_HANDLE_VALUE && ErrCode() == EINVAL) #endif - , 0666); + newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666); #endif if (newfd == INVALID_HANDLE_VALUE) { rc = ErrCode();