Commit f9d8449d authored by Michael Gardiner's avatar Michael Gardiner Committed by Alexandre Julliard

ole32: Stop StgOpenStorage from creating a file when it does not already exist.

parent d6ea1bf1
...@@ -5945,7 +5945,6 @@ HRESULT WINAPI StgOpenStorage( ...@@ -5945,7 +5945,6 @@ HRESULT WINAPI StgOpenStorage(
DWORD shareMode; DWORD shareMode;
DWORD accessMode; DWORD accessMode;
WCHAR fullname[MAX_PATH]; WCHAR fullname[MAX_PATH];
BOOL newFile;
TRACE("(%s, %p, %x, %p, %d, %p)\n", TRACE("(%s, %p, %x, %p, %d, %p)\n",
debugstr_w(pwcsName), pstgPriority, grfMode, debugstr_w(pwcsName), pstgPriority, grfMode,
...@@ -6035,24 +6034,13 @@ HRESULT WINAPI StgOpenStorage( ...@@ -6035,24 +6034,13 @@ HRESULT WINAPI StgOpenStorage(
*/ */
*ppstgOpen = 0; *ppstgOpen = 0;
if ((accessMode & GENERIC_WRITE) && /* try to create a file if no yet exists */ hFile = CreateFileW( pwcsName,
((hFile = CreateFileW( pwcsName, accessMode, shareMode, NULL, CREATE_NEW, accessMode,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 0)) shareMode,
!= INVALID_HANDLE_VALUE)) NULL,
{ OPEN_EXISTING,
newFile = TRUE; FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
} 0);
else
{
newFile = FALSE;
hFile = CreateFileW( pwcsName,
accessMode,
shareMode,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
0);
}
if (hFile==INVALID_HANDLE_VALUE) if (hFile==INVALID_HANDLE_VALUE)
{ {
...@@ -6090,7 +6078,7 @@ HRESULT WINAPI StgOpenStorage( ...@@ -6090,7 +6078,7 @@ HRESULT WINAPI StgOpenStorage(
* Refuse to open the file if it's too small to be a structured storage file * Refuse to open the file if it's too small to be a structured storage file
* FIXME: verify the file when reading instead of here * FIXME: verify the file when reading instead of here
*/ */
if (!newFile && GetFileSize(hFile, NULL) < 0x100) if (GetFileSize(hFile, NULL) < 0x100)
{ {
CloseHandle(hFile); CloseHandle(hFile);
hr = STG_E_FILEALREADYEXISTS; hr = STG_E_FILEALREADYEXISTS;
...@@ -6108,7 +6096,7 @@ HRESULT WINAPI StgOpenStorage( ...@@ -6108,7 +6096,7 @@ HRESULT WINAPI StgOpenStorage(
goto end; goto end;
} }
/* if we created new file, initialize the storage */ /* Initialize the storage */
hr = StorageImpl_Construct( hr = StorageImpl_Construct(
newStorage, newStorage,
hFile, hFile,
...@@ -6116,7 +6104,7 @@ HRESULT WINAPI StgOpenStorage( ...@@ -6116,7 +6104,7 @@ HRESULT WINAPI StgOpenStorage(
NULL, NULL,
grfMode, grfMode,
TRUE, TRUE,
newFile ); FALSE );
if (FAILED(hr)) if (FAILED(hr))
{ {
......
...@@ -388,12 +388,12 @@ static void test_open_storage(void) ...@@ -388,12 +388,12 @@ static void test_open_storage(void)
DeleteFileW(filename); DeleteFileW(filename);
/* try opening a nonexistent file - it should create it */ /* try opening a nonexistent file - it should not create it */
stgm = STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE; stgm = STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_READWRITE;
r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg); r = StgOpenStorage( filename, NULL, stgm, NULL, 0, &stg);
ok(r==S_OK, "StgOpenStorage failed: 0x%08x\n", r); ok(r!=S_OK, "StgOpenStorage failed: 0x%08x\n", r);
if (r==S_OK) IStorage_Release(stg); if (r==S_OK) IStorage_Release(stg);
ok(is_existing_file(filename), "StgOpenStorage didn't create a file\n"); ok(!is_existing_file(filename), "StgOpenStorage should not create a file\n");
DeleteFileW(filename); DeleteFileW(filename);
/* create the file */ /* create the file */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment