mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 10:50:53 +02:00
LazUtils: control how CopyFile works using flags. Issue #21854, modified from a patch from Takeda Matsuki
git-svn-id: trunk@37060 -
This commit is contained in:
parent
c53c098c48
commit
9fcb610a8e
@ -939,19 +939,8 @@ begin
|
||||
and (CompareFilenames(ExpDir,LeftStr(ExpFile,p))=0);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
function CopyFile(const SrcFilename, DestFilename: string): boolean;
|
||||
------------------------------------------------------------------------------}
|
||||
function CopyFile(const SrcFilename, DestFilename: string): boolean;
|
||||
begin
|
||||
Result := CopyFile(SrcFilename, DestFilename, false);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
function CopyFile(const SrcFilename, DestFilename: string PreserveTime:
|
||||
boolean): boolean;
|
||||
------------------------------------------------------------------------------}
|
||||
function CopyFile(const SrcFilename, DestFilename: String; PreserveTime: Boolean): Boolean;
|
||||
function CopyFile(const SrcFilename, DestFilename: String;
|
||||
Flags: TCopyFileFlags=[cffOverwriteFile]): Boolean;
|
||||
var
|
||||
SrcFS: TFileStreamUTF8;
|
||||
DestFS: TFileStreamUTF8;
|
||||
@ -959,13 +948,19 @@ begin
|
||||
try
|
||||
SrcFS := TFileStreamUTF8.Create(SrcFilename, fmOpenRead or fmShareDenyWrite);
|
||||
try
|
||||
if (not (cffOverwriteFile in Flags)) and FileExistsUTF8(DestFileName) then
|
||||
exit(False);
|
||||
if (cffCreateDestDirectory in Flags)
|
||||
and (not DirectoryExistsUTF8(ExtractFilePath(DestFileName)))
|
||||
and (not ForceDirectoriesUTF8(ExtractFilePath(DestFileName))) then
|
||||
exit(False);
|
||||
DestFS := TFileStreamUTF8.Create(DestFilename, fmCreate);
|
||||
try
|
||||
DestFS.CopyFrom(SrcFS, SrcFS.Size);
|
||||
finally
|
||||
DestFS.Free;
|
||||
end;
|
||||
if PreserveTime then
|
||||
if (cffPreserveTime in Flags) then
|
||||
FileSetDateUTF8(DestFilename, FileGetDate(SrcFS.Handle));
|
||||
finally
|
||||
SrcFS.Free;
|
||||
@ -974,6 +969,18 @@ begin
|
||||
except
|
||||
Result := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: Boolean): boolean;
|
||||
// Deparecated because Flags parameter can used for the same thing.
|
||||
var
|
||||
Flags: TCopyFileFlags;
|
||||
begin
|
||||
if PreserveTime then
|
||||
Flags:=[cffPreserveTime]
|
||||
else
|
||||
Flags:=[];
|
||||
Result := CopyFile(SrcFilename, DestFilename, Flags);
|
||||
end;
|
||||
|
||||
function GetTempFilename(const Directory, Prefix: string): string;
|
||||
|
@ -171,10 +171,22 @@ function FindAllFiles(const SearchPath: String; SearchMask: String = '';
|
||||
function FindAllDirectories(const SearchPath: string;
|
||||
SearchSubDirs: Boolean = True): TStringList;
|
||||
|
||||
// file copy
|
||||
type
|
||||
TCopyFileFlag = (
|
||||
cffOverwriteFile,
|
||||
cffCreateDestDirectory,
|
||||
cffPreserveTime
|
||||
);
|
||||
TCopyFileFlags = set of TCopyFileFlag;
|
||||
|
||||
// file actions
|
||||
function ReadFileToString(const Filename: string): string;
|
||||
function CopyFile(const SrcFilename, DestFilename: string): boolean;
|
||||
function CopyFile(const SrcFilename, DestFilename: string;
|
||||
Flags: TCopyFileFlags=[cffOverwriteFile]): boolean;
|
||||
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
|
||||
deprecated {$IFDEF VER2_5}'use cffPreserveTime in Flags parameter instead'{$ENDIF};
|
||||
|
||||
function GetTempFilename(const Directory, Prefix: string): string;
|
||||
|
||||
// basic functions similar to the RTL but working with UTF-8 instead of the
|
||||
|
Loading…
Reference in New Issue
Block a user