mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 12:40:22 +02:00
OpkMan: Erase all files in the destination directory before installation begins.
This commit is contained in:
parent
824e696005
commit
3e382c4b5b
@ -31,7 +31,7 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, contnrs,
|
||||
// LCL
|
||||
Dialogs, Forms, Controls,
|
||||
Dialogs, Forms, Controls, FileUtil,
|
||||
// LazUtils
|
||||
LazFileUtils, LazLoggerBase,
|
||||
// IdeIntf
|
||||
@ -150,6 +150,7 @@ procedure FindPackages(const ADirName: String; APackageList: TStrings);
|
||||
procedure FindAllFilesEx(const ADirName: String; AFileList: TStrings);
|
||||
function FixProtocol(const AURL: String): String;
|
||||
function IsDirectoryEmpty(const ADirectory: String): Boolean;
|
||||
function CleanDirectory(const ADirectory: String): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
@ -503,5 +504,49 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CleanDirectory(const ADirectory: String): Boolean;
|
||||
var
|
||||
SR: TSearchRec;
|
||||
DirName: String;
|
||||
Name: String;
|
||||
begin
|
||||
DirName := AppendPathDelim(ADirectory);
|
||||
if IsDirectoryEmpty(DirName) then
|
||||
RemoveDirUTF8(DirName);
|
||||
if FindFirst(DirName + '*', faAnyFile - faDirectory, SR) = 0 then
|
||||
begin
|
||||
try
|
||||
repeat
|
||||
if (SR.Name = '.') or (SR.Name = '..') or (SR.Name = '') then
|
||||
Continue;
|
||||
Name := DirName + SR.Name;
|
||||
if not DeleteFileUTF8(Name) then
|
||||
begin
|
||||
FileSetAttrUTF8(Name, faNormal);
|
||||
DeleteFileUTF8(Name);
|
||||
end;
|
||||
until FindNext(SR) <> 0;
|
||||
finally
|
||||
FindClose(SR);
|
||||
end;
|
||||
end;
|
||||
if FindFirst(DirName + '*', faAnyFile, SR) = 0 then
|
||||
begin
|
||||
try
|
||||
repeat
|
||||
if ((SR.Attr and faDirectory) <> 0) and (SR.Name <> '.') and (SR.Name <> '..') {$ifdef unix} and ((SR.Attr and faSymLink{%H-}) = 0) {$endif unix} then
|
||||
begin
|
||||
Name := DirName + SR.Name;
|
||||
FileSetAttrUTF8(Name, faNormal);
|
||||
CleanDirectory(DirName + SR.Name);
|
||||
end;
|
||||
until FindNext(SR) <> 0;
|
||||
finally
|
||||
FindClose(SR);
|
||||
end;
|
||||
end;
|
||||
Result := DeleteDirectory(ADirectory, False);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -424,7 +424,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
DeleteDirectory(DestDir, False);
|
||||
CleanDirectory(DestDir);
|
||||
end;
|
||||
if not CanGo then
|
||||
MessageDlgEx(rsCreateRepositoryFrm_Error4, mtError, [mbOk], Self)
|
||||
@ -629,7 +629,7 @@ begin
|
||||
Options.Changed := True;
|
||||
DestDir := AppendPathDelim(AppendPathDelim(ExtractFilePath(AFileName)) + 'Temp');
|
||||
if DirectoryExists(DestDir) then
|
||||
DeleteDirectory(DestDir, False);
|
||||
CleanDirectory(DestDir);
|
||||
Result := True;
|
||||
except
|
||||
on E: Exception do
|
||||
|
@ -1554,7 +1554,7 @@ begin
|
||||
begin
|
||||
if DirectoryExists(Options.LocalRepositoryPackagesExpanded + Items[I].PackageBaseDir) then
|
||||
begin
|
||||
DeleteDirectory(Options.LocalRepositoryPackagesExpanded + Items[I].PackageBaseDir, False);
|
||||
CleanDirectory(Options.LocalRepositoryPackagesExpanded + Items[I].PackageBaseDir);
|
||||
if not AlreadyCounted then
|
||||
Inc(Result);
|
||||
end;
|
||||
|
@ -158,9 +158,8 @@ begin
|
||||
FCurPos := 0;
|
||||
FZipFile := MPkg.RepositoryFileName;
|
||||
DelDir := FDstDir + MPkg.PackageBaseDir;
|
||||
if FIsUpdate then
|
||||
if DirectoryExists(DelDir) then
|
||||
DeleteDirectory(DelDir, False);
|
||||
if DirectoryExists(DelDir) then
|
||||
CleanDirectory(DelDir);
|
||||
try
|
||||
FUnZipper.Clear;
|
||||
FUnZipper.FileName := FSrcDir + MPkg.RepositoryFileName;
|
||||
@ -176,7 +175,7 @@ begin
|
||||
and (CompareText(MPkg.PackageBaseDir, MPkg.ZippedBaseDir) <> 0) then
|
||||
begin
|
||||
CopyDirTree(FUnZipper.OutputPath + MPkg.ZippedBaseDir, DelDir, [cffOverwriteFile]);
|
||||
DeleteDirectory(FUnZipper.OutputPath + MPkg.ZippedBaseDir, False);
|
||||
CleanDirectory(FUnZipper.OutputPath + MPkg.ZippedBaseDir);
|
||||
end;
|
||||
Synchronize(@DoOnZipProgress);
|
||||
FTotPos := FTotPos + FCurSize;
|
||||
@ -186,7 +185,7 @@ begin
|
||||
FErrMsg := E.Message;
|
||||
MPkg.ChangePackageStates(ctRemove, psExtracted);
|
||||
MPkg.ChangePackageStates(ctAdd, psError);
|
||||
DeleteDirectory(DelDir, False);
|
||||
CleanDirectory(DelDir);
|
||||
Synchronize(@DoOnZipError);
|
||||
end;
|
||||
end;
|
||||
@ -195,7 +194,7 @@ begin
|
||||
if (FNeedToBreak) then
|
||||
begin
|
||||
if DirectoryExists(DelDir) then
|
||||
DeleteDirectory(DelDir, False)
|
||||
CleanDirectory(DelDir);
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user