mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-24 06:14:47 +02:00
Fixed file attribute managing in FileManager::saveBuffer
Original code was flawed: * On +S+H (hidden and system) files, the attributes are set 4 times, when there's only need for 2 calls. * When clearing +S bit, it is masked out from the _original_ attribute value, which means that if the +H was cleared previously, it is set back again. It doesn't seem like this was intended, so I assume it's a bug. * When restoring the attributes, there's a pointless OR operation. Close #2881
This commit is contained in:
parent
bfb672d8bb
commit
23dd7228d0
@ -1002,8 +1002,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
|
|
||||||
EventReset reset(writeEvent); // Will reset event in destructor.
|
EventReset reset(writeEvent); // Will reset event in destructor.
|
||||||
Buffer* buffer = getBufferByID(id);
|
Buffer* buffer = getBufferByID(id);
|
||||||
bool isHidden = false;
|
bool isHiddenOrSys = false;
|
||||||
bool isSys = false;
|
|
||||||
DWORD attrib = 0;
|
DWORD attrib = 0;
|
||||||
|
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
@ -1019,13 +1018,9 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
|
|
||||||
if (attrib != INVALID_FILE_ATTRIBUTES)
|
if (attrib != INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
isHidden = (attrib & FILE_ATTRIBUTE_HIDDEN) != 0;
|
isHiddenOrSys = (attrib & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
|
||||||
if (isHidden)
|
if (isHiddenOrSys)
|
||||||
::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_HIDDEN);
|
::SetFileAttributes(filename, attrib & ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM));
|
||||||
|
|
||||||
isSys = (attrib & FILE_ATTRIBUTE_SYSTEM) != 0;
|
|
||||||
if (isSys)
|
|
||||||
::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_SYSTEM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,11 +1083,8 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHidden)
|
if (isHiddenOrSys)
|
||||||
::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_HIDDEN);
|
::SetFileAttributes(fullpath, attrib);
|
||||||
|
|
||||||
if (isSys)
|
|
||||||
::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_SYSTEM);
|
|
||||||
|
|
||||||
if (isCopy)
|
if (isCopy)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user