From a92506d82896596249f4d09f484f149d6cc24519 Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 25 Nov 2006 11:32:19 +0000 Subject: [PATCH] fixed bug #1542530 - WriteUninstaller fails to overwrite read-only uninstallers git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4822 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/exec.c | 4 ++-- Source/exehead/util.c | 11 +++++++++-- Source/exehead/util.h | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 4506d6c5..7fb50254 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -455,8 +455,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) // remove read only flag if overwrite mode is on if (!overwriteflag) { - int attr=GetFileAttributes(buf0); - SetFileAttributes(buf0,attr&(~FILE_ATTRIBUTE_READONLY)); + remove_ro_attr(buf0); } hOut=myOpenFile(buf0,GENERIC_WRITE,(overwriteflag==1)?CREATE_NEW:CREATE_ALWAYS); if (hOut == INVALID_HANDLE_VALUE) @@ -1445,6 +1444,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) } validate_filename(buf1); + remove_ro_attr(buf1); hFile=myOpenFile(buf1,GENERIC_WRITE,CREATE_ALWAYS); if (hFile != INVALID_HANDLE_VALUE) { diff --git a/Source/exehead/util.c b/Source/exehead/util.c index fa034e4e..15acbbe0 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -165,7 +165,7 @@ void NSISCALL myDelete(char *buf, int flags) else { log_printf2("Delete: DeleteFile(\"%s\")",buf); - SetFileAttributes(buf,fd.dwFileAttributes&(~FILE_ATTRIBUTE_READONLY)); + remove_ro_attr(buf); if (!DeleteFile(buf)) { #ifdef NSIS_SUPPORT_MOVEONREBOOT @@ -208,7 +208,7 @@ void NSISCALL myDelete(char *buf, int flags) { addtrailingslash(buf); log_printf2("RMDir: RemoveDirectory(\"%s\")",buf); - SetFileAttributes(buf,FILE_ATTRIBUTE_NORMAL); + remove_ro_attr(buf); if (!RemoveDirectory(buf)) { #ifdef NSIS_SUPPORT_MOVEONREBOOT @@ -370,6 +370,13 @@ void NSISCALL mini_memcpy(void *out, const void *in, int len) } } +void NSISCALL remove_ro_attr(char *file) +{ + int attr = GetFileAttributes(file); + if (attr != INVALID_FILE_ATTRIBUTES) + SetFileAttributes(file,attr&(~FILE_ATTRIBUTE_READONLY)); +} + HANDLE NSISCALL myOpenFile(const char *fn, DWORD da, DWORD cd) { int attr = GetFileAttributes(fn); diff --git a/Source/exehead/util.h b/Source/exehead/util.h index 8c0638ac..9a40dd73 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -90,6 +90,7 @@ int NSISCALL is_valid_instpath(char *s); void NSISCALL validate_filename(char *fn); void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew); void NSISCALL mini_memcpy(void *out, const void *in, int len); +void NSISCALL remove_ro_attr(char *file); void * NSISCALL myGetProcAddress(char *dll, char *func); void NSISCALL MessageLoop(UINT uCheckedMsg);