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

This commit is contained in:
Michael Gardiner 2007-01-01 15:09:51 +11:00 committed by Alexandre Julliard
parent d6ea1bf120
commit f9d8449db2
2 changed files with 13 additions and 25 deletions

View File

@ -5945,7 +5945,6 @@ HRESULT WINAPI StgOpenStorage(
DWORD shareMode;
DWORD accessMode;
WCHAR fullname[MAX_PATH];
BOOL newFile;
TRACE("(%s, %p, %x, %p, %d, %p)\n",
debugstr_w(pwcsName), pstgPriority, grfMode,
@ -6035,16 +6034,6 @@ HRESULT WINAPI StgOpenStorage(
*/
*ppstgOpen = 0;
if ((accessMode & GENERIC_WRITE) && /* try to create a file if no yet exists */
((hFile = CreateFileW( pwcsName, accessMode, shareMode, NULL, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 0))
!= INVALID_HANDLE_VALUE))
{
newFile = TRUE;
}
else
{
newFile = FALSE;
hFile = CreateFileW( pwcsName,
accessMode,
shareMode,
@ -6052,7 +6041,6 @@ HRESULT WINAPI StgOpenStorage(
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
0);
}
if (hFile==INVALID_HANDLE_VALUE)
{
@ -6090,7 +6078,7 @@ HRESULT WINAPI StgOpenStorage(
* 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
*/
if (!newFile && GetFileSize(hFile, NULL) < 0x100)
if (GetFileSize(hFile, NULL) < 0x100)
{
CloseHandle(hFile);
hr = STG_E_FILEALREADYEXISTS;
@ -6108,7 +6096,7 @@ HRESULT WINAPI StgOpenStorage(
goto end;
}
/* if we created new file, initialize the storage */
/* Initialize the storage */
hr = StorageImpl_Construct(
newStorage,
hFile,
@ -6116,7 +6104,7 @@ HRESULT WINAPI StgOpenStorage(
NULL,
grfMode,
TRUE,
newFile );
FALSE );
if (FAILED(hr))
{

View File

@ -388,12 +388,12 @@ static void test_open_storage(void)
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;
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);
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);
/* create the file */