Przeglądaj źródła

ADD: add system native copyfile() to support clone file on macOS

rich2014 2 miesięcy temu
rodzic
commit
14dc146845
2 zmienionych plików z 61 dodań i 1 usunięć
  1. 6 1
      src/doublecmd.lpi
  2. 55 0
      src/platform/unix/darwin/udarwinfileutil.pas

+ 6 - 1
src/doublecmd.lpi

@@ -328,7 +328,7 @@ end;"/>
         <PackageName Value="Image32"/>
       </Item13>
     </RequiredPackages>
-    <Units Count="289">
+    <Units Count="290">
       <Unit0>
         <Filename Value="doublecmd.lpr"/>
         <IsPartOfProject Value="True"/>
@@ -2101,6 +2101,11 @@ end;"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="uSmoothScrollingGrid"/>
       </Unit288>
+      <Unit289>
+        <Filename Value="platform\unix\darwin\udarwinfileutil.pas"/>
+        <IsPartOfProject Value="True"/>
+        <UnitName Value="uDarwinFileUtil"/>
+      </Unit289>
     </Units>
   </ProjectOptions>
   <CompilerOptions>

+ 55 - 0
src/platform/unix/darwin/udarwinfileutil.pas

@@ -0,0 +1,55 @@
+unit uDarwinFileUtil;
+
+{$mode ObjFPC}{$H+}
+{$modeswitch objectivec2}
+
+interface
+
+uses
+  Classes, SysUtils;
+
+type
+
+  { TDarwinFileUtil }
+
+  TDarwinFileUtil = class
+    class function cloneFile( const fromPath: String; const toPath: String ): Boolean;
+  end;
+
+implementation
+
+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
+  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;
+
+{ TDarwinFileUtil }
+
+class function TDarwinFileUtil.cloneFile( const fromPath: String; const toPath: String ): Boolean;
+var
+  ret: Integer;
+begin
+  ret:= copyfile( pchar(fromPath), pchar(toPath), nil, COPYFILE_ALL or COPYFILE_UNLINK or COPYFILE_CLONE_FORCE );
+  Result:= (ret=0);
+end;
+
+end.
+