summaryrefslogtreecommitdiff
path: root/zen/file_update_handle.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:20:07 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:20:07 +0200
commit88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170 (patch)
treec6c5babb49b90293380106b81ae5c446959ac70f /zen/file_update_handle.h
parent5.3 (diff)
downloadFreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.tar.gz
FreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.tar.bz2
FreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.zip
5.4
Diffstat (limited to 'zen/file_update_handle.h')
-rw-r--r--zen/file_update_handle.h33
1 files changed, 18 insertions, 15 deletions
diff --git a/zen/file_update_handle.h b/zen/file_update_handle.h
index 716048fd..3df69f10 100644
--- a/zen/file_update_handle.h
+++ b/zen/file_update_handle.h
@@ -18,25 +18,28 @@ public:
attr(INVALID_FILE_ATTRIBUTES)
{
hFile = cmd();
- if (hFile != INVALID_HANDLE_VALUE)
- return;
-
- const DWORD lastError = ::GetLastError();
- if (lastError == ERROR_ACCESS_DENIED) //function fails if file is read-only
+ if (hFile == INVALID_HANDLE_VALUE)
{
- //zen::ScopeGuard guardErrorCode = zen::makeGuard([&] { ::SetLastError(lastError); }); //transactional behavior: ensure cleanup (e.g. network drop) -> cref [!]
-
- //read-only file attribute may cause trouble: temporarily reset it
- const DWORD tmpAttr = ::GetFileAttributes(filenameFmt.c_str());
- if (tmpAttr != INVALID_FILE_ATTRIBUTES && (tmpAttr & FILE_ATTRIBUTE_READONLY))
+ //try to recover
+ if (::GetLastError() == ERROR_ACCESS_DENIED) //function fails if file is read-only
{
- if (::SetFileAttributes(filenameFmt.c_str(), FILE_ATTRIBUTE_NORMAL))
+ //read-only file attribute may cause trouble: temporarily reset it
+ const DWORD tmpAttr = ::GetFileAttributes(filenameFmt.c_str());
+ if (tmpAttr != INVALID_FILE_ATTRIBUTES)
{
- //guardErrorCode.dismiss();
- attr = tmpAttr; //"create" guard on read-only attribute
+ if (tmpAttr & FILE_ATTRIBUTE_READONLY)
+ {
+ if (::SetFileAttributes(filenameFmt.c_str(), FILE_ATTRIBUTE_NORMAL))
+ {
+ //guardErrorCode.dismiss();
+ attr = tmpAttr; //"create" guard on read-only attribute
- //now try again
- hFile = cmd();
+ //now try again
+ hFile = cmd();
+ }
+ }
+ else
+ ::SetLastError(ERROR_ACCESS_DENIED);
}
}
}
bgstack15