mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 18:49:19 +02:00
LazUtils: Better fix "Prevent CopyDirTree copying to a subdirectory of source." Issue #28841.
git-svn-id: trunk@51038 -
This commit is contained in:
parent
cc42e8d513
commit
10e166f60e
@ -696,6 +696,7 @@ end;
|
|||||||
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
|
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
|
||||||
var
|
var
|
||||||
Searcher: TCopyDirTree;
|
Searcher: TCopyDirTree;
|
||||||
|
Dummy: String;
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
Searcher:=TCopyDirTree.Create;
|
Searcher:=TCopyDirTree.Create;
|
||||||
@ -704,11 +705,13 @@ begin
|
|||||||
Flags:=Flags+[cffCreateDestDirectory];
|
Flags:=Flags+[cffCreateDestDirectory];
|
||||||
Searcher.FFlags:=Flags;
|
Searcher.FFlags:=Flags;
|
||||||
Searcher.FCopyFailedCount:=0;
|
Searcher.FCopyFailedCount:=0;
|
||||||
Searcher.FSourceDir:=TrimFilename(SetDirSeparators(SourceDir));
|
Searcher.FSourceDir:=LazFileUtils.TrimFilename(SetDirSeparators(SourceDir));
|
||||||
Searcher.FTargetDir:=TrimFilename(SetDirSeparators(TargetDir));
|
Searcher.FTargetDir:=LazFileUtils.TrimFilename(SetDirSeparators(TargetDir));
|
||||||
|
|
||||||
// Don't even try to copy to a subdirectory of SourceDir.
|
// Don't even try to copy to a subdirectory of SourceDir.
|
||||||
if {$if defined(Windows) or defined(darwin)}AnsiStartsText{$ELSE}AnsiStartsStr{$ENDIF}
|
if TryCreateRelativePath(LazFileUtils.ExpandFilenameUtf8(Searcher.FSourceDir),
|
||||||
(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
LazFileUtils.ExpandFilenameUtf8(Searcher.FTargetDir), False, True, {%H-}Dummy) then Exit;
|
||||||
|
|
||||||
Searcher.Search(SourceDir);
|
Searcher.Search(SourceDir);
|
||||||
Result:=Searcher.FCopyFailedCount=0;
|
Result:=Searcher.FCopyFailedCount=0;
|
||||||
finally
|
finally
|
||||||
|
@ -32,7 +32,7 @@ unit FileUtil;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, strutils,
|
Classes, SysUtils,
|
||||||
Masks, LazUTF8, LazFileUtils;
|
Masks, LazUTF8, LazFileUtils;
|
||||||
|
|
||||||
{$if defined(Windows) or defined(darwin)}
|
{$if defined(Windows) or defined(darwin)}
|
||||||
|
Loading…
Reference in New Issue
Block a user