From c27cc30e085e277735b7921aebe8e73168869e0e Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Sun, 21 Oct 2012 10:55:10 +0200 Subject: [PATCH] Installer: Make IsDirWritable() remove all its temporary dirs / files This fixes msysgit issue #66. Signed-off-by: Sebastian Schuberth --- share/WinGit/helpers.inc.iss | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/share/WinGit/helpers.inc.iss b/share/WinGit/helpers.inc.iss index 97dd90f1..a02a7ca4 100644 --- a/share/WinGit/helpers.inc.iss +++ b/share/WinGit/helpers.inc.iss @@ -63,24 +63,43 @@ begin end; end; -// Checks whether the specified directory can be created and written to. -// Note that the created dummy file is not explicitly deleted here, so that -// needs to be done as part of the uninstall process. +// Checks whether the specified directory can be created and written to +// by creating all intermediate directories and a temporary file. function IsDirWritable(DirName:String):Boolean; var - FileName:String; + AbsoluteDir,FirstExistingDir,FirstCreatedDir,FileName:String; begin - Result:=False; + Result:=True; + + AbsoluteDir:=ExpandFileName(DirName); - if not ForceDirectories(DirName) then begin - Exit; + FirstExistingDir:=AbsoluteDir; + while not DirExists(FirstExistingDir) do begin + FirstCreatedDir:=FirstExistingDir; + FirstExistingDir:=ExtractFileDir(FirstExistingDir); end; + Log('Line {#__LINE__}: First directory in hierarchy that already exists is "' + FirstExistingDir + '".') - FileName:=DirName+'\setup.ini'; + if Length(FirstCreatedDir)>0 then begin + Log('Line {#__LINE__}: First directory in hierarchy needs to be created is "' + FirstCreatedDir + '".') - if not SetIniBool('Dummy','Writable',true,FileName) then begin - Exit; - end; + if ForceDirectories(DirName) then begin + FileName:=GenerateUniqueName(DirName,'.txt'); + Log('Line {#__LINE__}: Trying to write to temporary file "' + Filename + '".') - Result:=GetIniBool('Dummy','Writable',false,FileName); + if SaveStringToFile(FileName,'This file is writable.',False) then begin + if not DeleteFile(FileName) then begin + Result:=False; + end; + end else begin + Result:=False; + end; + end else begin + Result:=False; + end; + + if not DelTree(FirstCreatedDir,True,False,True) then begin + Result:=False; + end; + end; end; -- 2.11.4.GIT