mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Save XML-config into symbolic link
(cherry picked from commit 7f38508f46)
This commit is contained in:
parent
c379b11318
commit
0032175085
2 changed files with 35 additions and 10 deletions
|
|
@ -111,6 +111,12 @@ function FPS_ISDIR(iAttr: TFileAttrs) : Boolean;
|
|||
@returns(@true if file is a symbolic link, @false otherwise)
|
||||
}
|
||||
function FPS_ISLNK(iAttr: TFileAttrs) : Boolean;
|
||||
{en
|
||||
Is file a regular file
|
||||
@param(iAttr File attributes)
|
||||
@returns(@true if file is a regular file, @false otherwise)
|
||||
}
|
||||
function FPS_ISREG(iAttr: TFileAttrs) : Boolean;
|
||||
{en
|
||||
Is file executable
|
||||
@param(sFileName File name)
|
||||
|
|
@ -385,8 +391,6 @@ const
|
|||
O_SYNC or O_DIRECT);
|
||||
{$ENDIF}
|
||||
|
||||
(*Is Directory*)
|
||||
|
||||
function FPS_ISDIR(iAttr: TFileAttrs) : Boolean; inline;
|
||||
{$IFDEF MSWINDOWS}
|
||||
begin
|
||||
|
|
@ -398,8 +402,6 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
(*Is Link*)
|
||||
|
||||
function FPS_ISLNK(iAttr: TFileAttrs) : Boolean; inline;
|
||||
{$IFDEF MSWINDOWS}
|
||||
begin
|
||||
|
|
@ -411,6 +413,17 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FPS_ISREG(iAttr: TFileAttrs) : Boolean; inline;
|
||||
{$IFDEF MSWINDOWS}
|
||||
begin
|
||||
Result := (iAttr and FILE_ATTRIBUTE_DIRECTORY = 0);
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
Result := BaseUnix.FPS_ISREG(TMode(iAttr));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FileIsExeLib(const sFileName : String) : Boolean;
|
||||
var
|
||||
fsExeLib : TFileStreamEx;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
Based on XmlConf from fcl-xml package.
|
||||
|
||||
Copyright (C) 2010 Przemyslaw Nagay (cobines@gmail.com)
|
||||
Copyright (C) 2013-2023 Alexander Koblov (alexx2000@mail.ru)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -21,6 +22,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
}
|
||||
|
||||
unit DCXmlConfig;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
|
@ -149,7 +151,7 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
LazLogger, DCOSUtils, DCClassesUtf8, URIParser;
|
||||
LazLogger, DCBasicTypes, DCOSUtils, DCClassesUtf8, URIParser;
|
||||
|
||||
const
|
||||
BoolStrings: array[Boolean] of DOMString = ('False', 'True');
|
||||
|
|
@ -611,6 +613,8 @@ end;
|
|||
|
||||
function TXmlConfig.Save: Boolean;
|
||||
var
|
||||
AFileName: String;
|
||||
dwAttr: TFileAttrs;
|
||||
bFileExists: Boolean;
|
||||
sTmpConfigFileName: String;
|
||||
begin
|
||||
|
|
@ -619,17 +623,25 @@ begin
|
|||
if FFileName = '' then
|
||||
Exit;
|
||||
|
||||
bFileExists := mbFileExists(FileName);
|
||||
dwAttr := mbFileGetAttr(FileName);
|
||||
bFileExists := (dwAttr <> faInvalidAttributes) and (FPS_ISREG(dwAttr));
|
||||
|
||||
if FPS_ISLNK(dwAttr) then
|
||||
AFileName := mbReadAllLinks(FileName)
|
||||
else begin
|
||||
AFileName := FileName;
|
||||
end;
|
||||
|
||||
// Write to temporary file and if successfully written rename to proper name.
|
||||
if (not bFileExists) or mbFileAccess(FileName, fmOpenWrite or fmShareDenyWrite) then
|
||||
if (not bFileExists) or mbFileAccess(AFileName, fmOpenWrite or fmShareDenyWrite) then
|
||||
begin
|
||||
sTmpConfigFileName := GetTempName(FileName);
|
||||
sTmpConfigFileName := GetTempName(AFileName);
|
||||
try
|
||||
WriteToFile(sTmpConfigFileName);
|
||||
if bFileExists then begin
|
||||
mbFileCopyAttr(FileName, sTmpConfigFileName, [caoCopyOwnership, caoCopyPermissions]);
|
||||
mbFileCopyAttr(AFileName, sTmpConfigFileName, [caoCopyOwnership, caoCopyPermissions]);
|
||||
end;
|
||||
if not mbRenameFile(sTmpConfigFileName, FileName) then
|
||||
if not mbRenameFile(sTmpConfigFileName, AFileName) then
|
||||
begin
|
||||
mbDeleteFile(sTmpConfigFileName);
|
||||
DebugLogger.Debugln('Cannot save configuration file ', FileName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue