Commit d1e2f812 authored by sfalken@apple.com's avatar sfalken@apple.com

Added our own mechanism for generating temporary file names.

        
        Reviewed by Ada Chan, Darin Adler.

        * platform/win/FileSystemWin.cpp:
        (WebCore::openTemporaryFile):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34746 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3d55fe7f
2008-06-23 Steve Falkenburg <sfalken@apple.com>
Added our own mechanism for generating temporary file names.
Reviewed by Ada Chan, Darin Adler.
* platform/win/FileSystemWin.cpp:
(WebCore::openTemporaryFile):
2008-06-23 Sam Weinig <sam@webkit.org>
Remove XMLHttpRequestProgressEvent.cpp from project files.
......@@ -184,25 +184,49 @@ static String cachedStorageDirectory(DWORD pathIdentifier)
return directory;
}
CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle)
CString openTemporaryFile(const char*, PlatformFileHandle& handle)
{
handle = INVALID_HANDLE_VALUE;
char tempPath[MAX_PATH];
int tempPathLength = ::GetTempPathA(_countof(tempPath), tempPath);
if (tempPathLength <= 0 || tempPathLength > _countof(tempPath))
return 0;
char tempFile[MAX_PATH];
if (::GetTempFileNameA(tempPath, prefix, 0, tempFile) > 0) {
HANDLE tempHandle = ::CreateFileA(tempFile, GENERIC_READ | GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HCRYPTPROV hCryptProv = 0;
if (!CryptAcquireContext(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
return 0;
if (isHandleValid(tempHandle)) {
handle = tempHandle;
return tempFile;
}
char proposedPath[MAX_PATH];
while (1) {
char tempFile[] = "XXXXXXXX.tmp"; // Use 8.3 style name (more characters aren't helpful due to 8.3 short file names)
const int randomPartLength = 8;
if (!CryptGenRandom(hCryptProv, randomPartLength, reinterpret_cast<BYTE*>(tempFile)))
break;
// Limit to valid filesystem characters, also excluding others that could be problematic, like punctuation.
// don't include both upper and lowercase since Windows file systems are typically not case sensitive.
const char validChars[] = "0123456789abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < randomPartLength; ++i)
tempFile[i] = validChars[tempFile[i] % sizeof(validChars)];
if (!PathCombineA(proposedPath, tempPath, tempFile))
break;
// use CREATE_NEW to avoid overwriting an existing file with the same name
handle = CreateFileA(proposedPath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
if (!isHandleValid(handle) && GetLastError() == ERROR_ALREADY_EXISTS)
continue;
break;
}
return 0;
CryptReleaseContext(hCryptProv, 0);
if (!isHandleValid(handle))
return 0;
return proposedPath;
}
void closeFile(PlatformFileHandle& handle)
......
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