[BUG_FIXED] (Author: Andreas Jonsson) Fix opening the same file twice due to its different path (symbol link).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1056 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
7e66078bed
commit
fe5b147fe3
@ -893,6 +893,7 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
BufferID FileManager::getBufferFromName(const TCHAR * name) {
|
||||
TCHAR fullpath[MAX_PATH];
|
||||
::GetFullPathName(name, MAX_PATH, fullpath, NULL);
|
||||
@ -903,6 +904,60 @@ BufferID FileManager::getBufferFromName(const TCHAR * name) {
|
||||
}
|
||||
return BUFFER_INVALID;
|
||||
}
|
||||
*/
|
||||
|
||||
BufferID FileManager::getBufferFromName(const TCHAR * name)
|
||||
{
|
||||
HANDLE givenFile = ::CreateFile(name,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
BY_HANDLE_FILE_INFORMATION givenFileInfo, currentFileInfo;
|
||||
|
||||
if(givenFile == INVALID_HANDLE_VALUE)
|
||||
return BUFFER_INVALID;
|
||||
|
||||
if(! ::GetFileInformationByHandle(givenFile, &givenFileInfo))
|
||||
{
|
||||
::CloseHandle(givenFile);
|
||||
return BUFFER_INVALID;
|
||||
}
|
||||
|
||||
::CloseHandle(givenFile);
|
||||
|
||||
const unsigned int bufferSize = _buffers.size();
|
||||
for(size_t i = 0; i < bufferSize; i++)
|
||||
{
|
||||
HANDLE currentFile = ::CreateFile(_buffers.at(i)->getFullPathName(),
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
if(currentFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if(::GetFileInformationByHandle(currentFile, ¤tFileInfo))
|
||||
{
|
||||
if(currentFileInfo.dwVolumeSerialNumber == givenFileInfo.dwVolumeSerialNumber &&
|
||||
currentFileInfo.nFileIndexLow == givenFileInfo.nFileIndexLow &&
|
||||
currentFileInfo.nFileIndexHigh == givenFileInfo.nFileIndexHigh)
|
||||
{
|
||||
::CloseHandle(currentFile);
|
||||
return _buffers.at(i)->getID();
|
||||
}
|
||||
}
|
||||
::CloseHandle(currentFile);
|
||||
}
|
||||
}
|
||||
|
||||
return BUFFER_INVALID;
|
||||
}
|
||||
|
||||
BufferID FileManager::getBufferFromDocument(Document doc) {
|
||||
for(size_t i = 0; i < _nrBufs; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user