ADD #2500: support copying extended attributes

This commit is contained in:
rich2014 2025-09-21 21:45:15 +08:00
commit 47c57a80a5
2 changed files with 38 additions and 1 deletions

View file

@ -14,6 +14,7 @@ const
CLOSE_RANGE_CLOEXEC = (1 << 2);
function CloseRange(first: cuint; last: cuint; flags: cint): cint; cdecl;
function mbFileCopyXattr(const Source, Target: String): Boolean;
// MacOS File Utils
function MacosFileSetCreationTime( const path:String; const birthtime:TFileTimeEx ): Boolean;
@ -30,10 +31,33 @@ type
end;
Pproc_fdinfo = ^proc_fdinfo;
type
copyfile_state_t_o = record
end;
copyfile_state_t = ^copyfile_state_t_o;
copyfile_flags_t = UInt32;
function copyfile( const fromPath: pchar; const toPath: pchar; state: copyfile_state_t; flags: copyfile_flags_t ): Integer;
cdecl; external name 'copyfile';
const
PROC_PIDLISTFDS = 1;
PROC_PIDLISTFD_SIZE = SizeOf(proc_fdinfo);
const
COPYFILE_ACL = 1 shl 0;
COPYFILE_STAT = 1 shl 1;
COPYFILE_XATTR = 1 shl 2;
COPYFILE_DATA = 1 shl 3;
COPYFILE_SECURITY = COPYFILE_STAT or COPYFILE_ACL;
COPYFILE_METADATA = COPYFILE_SECURITY or COPYFILE_XATTR;
COPYFILE_ALL = COPYFILE_METADATA or COPYFILE_DATA;
COPYFILE_UNLINK = 1 shl 21;
COPYFILE_CLONE = 1 shl 24;
COPYFILE_CLONE_FORCE = 1 shl 25;
function proc_pidinfo(pid: cint; flavor: cint; arg: cuint64; buffer: pointer; buffersize: cint): cint; cdecl; external 'proc';
function CloseRange(first: cuint; last: cuint; flags: cint): cint; cdecl;
@ -68,6 +92,16 @@ begin
end;
end;
function mbFileCopyXattr(const Source, Target: String): Boolean;
var
ret: Integer;
begin
Writeln( '>>3> mbFileCopyXattr' );
ret:= copyfile( pchar(Source), pchar(Target), nil, COPYFILE_XATTR );
fpseterrno( ret );
Result:= (ret=0);
end;
function StringToNSString(const S: String): NSString;
begin
Result:= NSString(NSString.stringWithUTF8String(PAnsiChar(S)));

View file

@ -34,6 +34,9 @@ uses
{$IFDEF LINUX}
, DCLinux
{$ENDIF}
{$IFDEF DARWIN}
, DCDarwin
{$ENDIF}
{$IFDEF HAIKU}
, DCHaiku
{$ENDIF}
@ -654,7 +657,7 @@ begin
end;
end;
{$IF DEFINED(LINUX) or DEFINED(HAIKU)}
{$IF DEFINED(LINUX) or DEFINED(DARWIN) or DEFINED(HAIKU)}
if caoCopyXattributes in Options then
begin
if not mbFileCopyXattr(sSrc, sDst) then