Merged revision(s) 51033-51034 #6faa4e893c-#6faa4e893c, 51038-51039 #10e166f60e-#10e166f60e, 51041 #35b30db335 from trunk:

LazUtils: Prevent CopyDirTree copying to a subdirectory of source. Issue .
........
LazUtils: Use trimmed paths for comparing sub-dir in CopyDirTree. Fix return value. Issue .
........
LazUtils: Better fix "Prevent CopyDirTree copying to a subdirectory of source." Issue .
........
LazUtils: Fix r51038 #10e166f60e for Issue .
........
LazUtils: CopyDirTree: better readable Boolean expression.
........

git-svn-id: branches/fixes_1_6@51078 -
This commit is contained in:
maxim 2015-12-28 22:21:41 +00:00
parent beecbb57ad
commit 015fc4f7b7

View File

@ -696,6 +696,8 @@ end;
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
var
Searcher: TCopyDirTree;
RelPath: String;
B: Boolean;
begin
Result:=False;
Searcher:=TCopyDirTree.Create;
@ -704,12 +706,17 @@ begin
Flags:=Flags+[cffCreateDestDirectory];
Searcher.FFlags:=Flags;
Searcher.FCopyFailedCount:=0;
Searcher.FSourceDir:=SetDirSeparators(SourceDir);
Searcher.FTargetDir:=SetDirSeparators(TargetDir);
Searcher.FSourceDir:=LazFileUtils.TrimFilename(SetDirSeparators(SourceDir));
Searcher.FTargetDir:=LazFileUtils.TrimFilename(SetDirSeparators(TargetDir));
// Don't even try to copy to a subdirectory of SourceDir.
B := TryCreateRelativePath(LazFileUtils.ExpandFilenameUtf8(Searcher.FSourceDir),
LazFileUtils.ExpandFilenameUtf8(Searcher.FTargetDir), False, True, RelPath);
if B and ((Copy(RelPath,1,2) = '..') or (RelPath = '')) then Exit;
Searcher.Search(SourceDir);
Result:=True;
finally
Result:=Searcher.FCopyFailedCount=0;
finally
Searcher.Free;
end;
end;