From 67efbda4a22dcf0868df18cc1280ffa6a33d0ecd Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 27 Apr 2013 02:49:43 +0200 Subject: [PATCH 1/3] Print actual Win32 error that occurred on file creation failure. --- src/leveldb/util/env_win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index f1a76106..c64027f6 100644 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -971,7 +971,7 @@ Status Win32Env::NewRandomAccessFile( const std::string& fname, RandomAccessFile if(!pFile->isEnable()){ delete pFile; *result = NULL; - sRet = Status::IOError(path,"Could not create random access file."); + sRet = Status::IOError(path, Win32::GetLastErrSz()); }else *result = pFile; return sRet; From 20d6f2013b6629566b3fe1b5b03800fecac25e96 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 27 Apr 2013 20:07:22 +0200 Subject: [PATCH 2/3] Checking whether closing succeeds --- src/leveldb/util/env_win.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index c64027f6..4730192b 100644 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -462,8 +462,8 @@ bool Win32MapFile::_UnmapCurrentRegion() // Defer syncing this data until next Sync() call, if any _pending_sync = true; } - UnmapViewOfFile(_base); - CloseHandle(_base_handle); + if (!UnmapViewOfFile(_base) || !CloseHandle(_base_handle)) + result = false; _file_offset += _limit - _base; _base = NULL; _base_handle = NULL; From 551b367f19dce1951362a1f9911004e583732376 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 28 Apr 2013 14:15:34 +0200 Subject: [PATCH 3/3] Allow files to be opened for reading multiple times --- src/leveldb/util/env_win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index 4730192b..ef2ecae8 100644 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -420,7 +420,7 @@ BOOL Win32RandomAccessFile::_Init( LPCWSTR path ) { BOOL bRet = FALSE; if(!_hFile) - _hFile = ::CreateFileW(path,GENERIC_READ,0,NULL,OPEN_EXISTING, + _hFile = ::CreateFileW(path,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,NULL); if(!_hFile || _hFile == INVALID_HANDLE_VALUE ) _hFile = NULL;