mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-06 08:20:24 +02:00
MG: backuping files now save file attributes/permissions
git-svn-id: trunk@1684 -
This commit is contained in:
parent
78372e4147
commit
15aa57881a
@ -41,6 +41,7 @@ const
|
|||||||
function FilenameIsAbsolute(Filename: string):boolean;
|
function FilenameIsAbsolute(Filename: string):boolean;
|
||||||
function DirectoryExists(DirectoryName: string): boolean;
|
function DirectoryExists(DirectoryName: string): boolean;
|
||||||
function ForceDirectory(DirectoryName: string): boolean;
|
function ForceDirectory(DirectoryName: string): boolean;
|
||||||
|
function BackupFile(const Filename, BackupFilename: string): boolean;
|
||||||
function ExtractFileNameOnly(const AFilename: string): string;
|
function ExtractFileNameOnly(const AFilename: string): string;
|
||||||
procedure CheckIfFileIsExecutable(const AFilename: string);
|
procedure CheckIfFileIsExecutable(const AFilename: string);
|
||||||
function FileIsExecutable(const AFilename: string): boolean;
|
function FileIsExecutable(const AFilename: string): boolean;
|
||||||
@ -489,4 +490,46 @@ begin
|
|||||||
Obj:=nil;
|
Obj:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{-------------------------------------------------------------------------------
|
||||||
|
BackupFile
|
||||||
|
|
||||||
|
Params: const Filename, BackupFilename: string
|
||||||
|
Result: boolean
|
||||||
|
|
||||||
|
Rename Filename to Backupfilename and create empty Filename with same
|
||||||
|
file attributes
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function BackupFile(const Filename, BackupFilename: string): boolean;
|
||||||
|
var
|
||||||
|
FHandle: Integer;
|
||||||
|
{$IFDEF Win32}
|
||||||
|
OldAttr: Longint;
|
||||||
|
{$ELSE}
|
||||||
|
OldInfo: Stat;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
// store file attributes
|
||||||
|
{$IFDEF Win32}
|
||||||
|
OldAttr:=FileGetAttr(Filename);
|
||||||
|
{$ELSE}
|
||||||
|
FStat(Filename,OldInfo);
|
||||||
|
{$ENDIF}
|
||||||
|
// rename file
|
||||||
|
if not RenameFile(Filename,BackupFilename) then exit;
|
||||||
|
// create empty file
|
||||||
|
FHandle:=FileCreate(FileName);
|
||||||
|
FileClose(FHandle);
|
||||||
|
// restore file attributes
|
||||||
|
{$IFDEF Win32}
|
||||||
|
FileSetAttr(FileName,OldAttr);
|
||||||
|
{$ELSE}
|
||||||
|
Chmod(Filename,
|
||||||
|
OldInfo.Mode and (STAT_IRWXO+STAT_IRWXG+STAT_IRWXU
|
||||||
|
+STAT_ISUID+STAT_ISGID+STAT_ISVTX));
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
21
ide/main.pp
21
ide/main.pp
@ -4733,6 +4733,15 @@ begin
|
|||||||
until Result<>mrRetry;
|
until Result<>mrRetry;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{-------------------------------------------------------------------------------
|
||||||
|
TMainIDE DoBackupFile
|
||||||
|
|
||||||
|
Params: const Filename:string;
|
||||||
|
IsPartOfProject:boolean
|
||||||
|
Returns: TModalResult
|
||||||
|
|
||||||
|
Rename existing file to backup file.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
function TMainIDE.DoBackupFile(const Filename:string;
|
function TMainIDE.DoBackupFile(const Filename:string;
|
||||||
IsPartOfProject:boolean): TModalResult;
|
IsPartOfProject:boolean): TModalResult;
|
||||||
var BackupFilename, CounterFilename: string;
|
var BackupFilename, CounterFilename: string;
|
||||||
@ -4752,8 +4761,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
FilePath:=ExtractFilePath(Filename);
|
FilePath:=ExtractFilePath(Filename);
|
||||||
FileExt:=ExtractFileExt(Filename);
|
FileExt:=ExtractFileExt(Filename);
|
||||||
FileNameOnly:=ExtractFilename(Filename);
|
FileNameOnly:=ExtractFilenameOnly(Filename);
|
||||||
FileNameOnly:=copy(FilenameOnly,1,length(FilenameOnly)-length(FileExt));
|
|
||||||
if BackupInfo.SubDirectory<>'' then begin
|
if BackupInfo.SubDirectory<>'' then begin
|
||||||
SubDir:=FilePath+BackupInfo.SubDirectory;
|
SubDir:=FilePath+BackupInfo.SubDirectory;
|
||||||
repeat
|
repeat
|
||||||
@ -4853,9 +4861,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
// backup file
|
// backup file
|
||||||
repeat
|
repeat
|
||||||
if not RenameFile(Filename,BackupFilename) then begin
|
if not BackupFile(Filename,BackupFilename) then begin
|
||||||
ACaption:='Rename file failed';
|
ACaption:='Backup file failed';
|
||||||
AText:='Unable to rename file "'+Filename+'" to "'+BackupFilename+'"!';
|
AText:='Unable to backup file "'+Filename+'" to "'+BackupFilename+'"!';
|
||||||
Result:=MessageDlg(ACaption,AText,mterror,[mbabort,mbretry,mbignore],0);
|
Result:=MessageDlg(ACaption,AText,mterror,[mbabort,mbretry,mbignore],0);
|
||||||
if Result=mrAbort then exit;
|
if Result=mrAbort then exit;
|
||||||
if Result=mrIgnore then Result:=mrOk;
|
if Result=mrIgnore then Result:=mrOk;
|
||||||
@ -6362,6 +6370,9 @@ end.
|
|||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.296 2002/05/16 14:01:45 lazarus
|
||||||
|
MG: backuping files now save file attributes/permissions
|
||||||
|
|
||||||
Revision 1.295 2002/05/16 13:00:55 lazarus
|
Revision 1.295 2002/05/16 13:00:55 lazarus
|
||||||
MG: fixed changing syntax highlighter on save as
|
MG: fixed changing syntax highlighter on save as
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user