Prechádzať zdrojové kódy

UPD: ShowFileProperties: show Creation time on MacOS (#939)

rich2014 2 rokov pred
rodič
commit
92a24d1666

+ 6 - 59
components/doublecmd/dcosutils.pas

@@ -17,11 +17,6 @@
 
    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-   Notes:
-   1. TDarwinStat64 is the workaround for the bug of BaseUnix.Stat in FPC.
-      on MacOS with x86_64, Stat64 should be used instead of Stat.
-      and lstat64() should be called instead of lstat().
 }
 
 unit DCOSUtils;
@@ -56,37 +51,6 @@ const
 {$ENDIF}
 
 type
-{$IF DEFINED(DARWIN)}
-  TDarwinStat64 = record { the types are real}
-       st_dev        : dev_t;             // inode's device
-       st_mode       : mode_t;            // inode protection mode
-       st_nlink      : nlink_t;           // number of hard links
-       st_ino        : cuint64;             // inode's number
-       st_uid        : uid_t;             // user ID of the file's owner
-       st_gid        : gid_t;             // group ID of the file's group
-       st_rdev       : dev_t;             // device type
-       st_atime      : time_t;            // time of last access
-       st_atimensec  : clong;             // nsec of last access
-       st_mtime      : time_t;            // time of last data modification
-       st_mtimensec  : clong;             // nsec of last data modification
-       st_ctime      : time_t;            // time of last file status change
-       st_ctimensec  : clong;             // nsec of last file status change
-       st_birthtime  : time_t;            // File creation time
-       st_birthtimensec : clong;          // nsec of file creation time
-       st_size       : off_t;             // file size, in bytes
-       st_blocks     : cint64;            // blocks allocated for file
-       st_blksize    : cuint32;           // optimal blocksize for I/O
-       st_flags      : cuint32;           // user defined flags for file
-       st_gen        : cuint32;           // file generation number
-       st_lspare     : cint32;
-       st_qspare     : array[0..1] Of cint64;
-  end;
-
-  TDCStat = TDarwinStat64;
-{$ELSE}
-  TDCStat = BaseUnix.Stat;
-{$ENDIF}
-
   TFileMapRec = record
     FileHandle : System.THandle;
     FileSize : Int64;
@@ -345,27 +309,6 @@ uses
 {$ENDIF}
   DCStrUtils, LazUTF8;
 
-{$IF DEFINED(DARWIN)}
-
-Function fpLstat64( path:pchar; Info:pstat ): cint; cdecl; external clib name 'lstat64';
-
-Function DC_fpLstat( const path:RawByteString; var Info:TDCStat ): cint; inline;
-var
-  SystemPath: RawByteString;
-begin
-  SystemPath:=ToSingleByteFileSystemEncodedFileName( path );
-  Result:= fpLstat64( pchar(SystemPath), @info );
-end;
-
-{$ELSE}
-
-Function DC_fpLstat( const path:RawByteString; var Info:TDCStat ): cint; inline;
-begin
-  fpLstat( path, info );
-end;
-
-{$ENDIF}
-
 {$IFDEF UNIX}
 function SetModeReadOnly(mode: TMode; ReadOnly: Boolean): TMode;
 begin
@@ -971,14 +914,18 @@ begin
 end;
 {$ELSE}
 var
-  StatInfo : BaseUnix.Stat;
+  StatInfo : TDCStat;
 begin
-  Result := fpLStat(UTF8ToSys(FileName), StatInfo) >= 0;
+  Result := DC_fpLStat(UTF8ToSys(FileName), StatInfo) >= 0;
   if Result then
   begin
     LastAccessTime   := StatInfo.st_atime;
     ModificationTime := StatInfo.st_mtime;
+    {$IF DEFINED(DARWIN)}
+    CreationTime     := StatInfo.st_birthtime;
+    {$ELSE}
     CreationTime     := StatInfo.st_ctime;
+    {$ENDIF}
   end;
 end;
 {$ENDIF}

+ 65 - 1
components/doublecmd/dcunix.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    This unit contains Unix specific functions
 
-   Copyright (C) 2015-2022 Alexander Koblov ([email protected])
+   Copyright (C) 2015-2023 Alexander Koblov ([email protected])
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,11 @@
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+   Notes:
+   1. TDarwinStat64 is the workaround for the bug of BaseUnix.Stat in FPC.
+      on MacOS with x86_64, Stat64 should be used instead of Stat.
+      and lstat64() should be called instead of lstat().
 }
 
 unit DCUnix;
@@ -118,6 +123,41 @@ type
   TGroupRecord = group;
   PGroupRecord = ^TGroupRecord;
 
+type
+{$IF DEFINED(DARWIN)}
+  TDarwinStat64 = record { the types are real}
+       st_dev        : dev_t;             // inode's device
+       st_mode       : mode_t;            // inode protection mode
+       st_nlink      : nlink_t;           // number of hard links
+       st_ino        : cuint64;           // inode's number
+       st_uid        : uid_t;             // user ID of the file's owner
+       st_gid        : gid_t;             // group ID of the file's group
+       st_rdev       : dev_t;             // device type
+       st_atime      : time_t;            // time of last access
+       st_atimensec  : clong;             // nsec of last access
+       st_mtime      : time_t;            // time of last data modification
+       st_mtimensec  : clong;             // nsec of last data modification
+       st_ctime      : time_t;            // time of last file status change
+       st_ctimensec  : clong;             // nsec of last file status change
+       st_birthtime  : time_t;            // File creation time
+       st_birthtimensec : clong;          // nsec of file creation time
+       st_size       : off_t;             // file size, in bytes
+       st_blocks     : cint64;            // blocks allocated for file
+       st_blksize    : cuint32;           // optimal blocksize for I/O
+       st_flags      : cuint32;           // user defined flags for file
+       st_gen        : cuint32;           // file generation number
+       st_lspare     : cint32;
+       st_qspare     : array[0..1] Of cint64;
+  end;
+
+  TDCStat = TDarwinStat64;
+{$ELSE}
+  TDCStat = BaseUnix.Stat;
+{$ENDIF}
+
+Function DC_fpLstat( const path:RawByteString; var Info:TDCStat ): cint; inline;
+
+
 {en
    Set the close-on-exec flag to all
 }
@@ -211,6 +251,30 @@ implementation
 uses
   Unix, DCConvertEncoding;
 
+
+{$IF DEFINED(DARWIN)}
+
+Function fpLstat64( path:pchar; Info:pstat ): cint; cdecl; external clib name 'lstat64';
+
+Function DC_fpLstat( const path:RawByteString; var Info:TDCStat ): cint; inline;
+var
+  SystemPath: RawByteString;
+begin
+  SystemPath:=ToSingleByteFileSystemEncodedFileName( path );
+  Result:= fpLstat64( pchar(SystemPath), @info );
+end;
+
+{$ELSE}
+
+Function DC_fpLstat( const path:RawByteString; var Info:TDCStat ): cint; inline;
+begin
+  fpLstat( path, info );
+end;
+
+{$ENDIF}
+
+
+
 {$IF DEFINED(BSD)}
 type rlim_t = Int64;
 {$ENDIF}

+ 27 - 1
src/ffileproperties.lfm

@@ -8,7 +8,7 @@ object frmFileProperties: TfrmFileProperties
   ChildSizing.LeftRightSpacing = 8
   ClientHeight = 471
   ClientWidth = 458
-  Constraints.MinHeight = 432
+  Constraints.MinHeight = 450
   Constraints.MinWidth = 458
   KeyPreview = True
   OnCreate = FormCreate
@@ -290,6 +290,32 @@ object frmFileProperties: TfrmFileProperties
           )
           ReadOnly = True
         end
+       object lblCreatedStr: TLabel
+          AnchorSideTop.Side = asrBottom
+          Left = 10
+          Height = 17
+          Top = 261
+          Width = 119
+          BorderSpacing.Top = 2
+          BorderSpacing.CellAlignVertical = ccaCenter
+          Caption = 'Created:'
+          ParentColor = False
+        end
+        object lblCreated: TKASCDEdit
+          AnchorSideTop.Side = asrBottom
+          AnchorSideRight.Side = asrBottom
+          Cursor = crIBeam
+          Left = 128
+          Height = 23
+          Top = 258
+          Width = 25
+          AutoSize = True
+          DrawStyle = dsExtra1
+          Lines.Strings = (
+            '???'
+          )
+          ReadOnly = True
+        end
       end
     end
     object tsAttributes: TTabSheet

+ 10 - 1
src/ffileproperties.pas

@@ -5,7 +5,7 @@
 
    Copyright (C) 2003-2004 Radek Cervinka ([email protected])
    Copyright (C) 2003 Martin Matusu <[email protected]>
-   Copyright (C) 2006-2018 Alexander Koblov ([email protected])
+   Copyright (C) 2006-2023 Alexander Koblov ([email protected])
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -72,6 +72,8 @@ type
     lblLastModifStr: TLabel;
     lblLastStChange: TKASCDEdit;
     lblLastStChangeStr: TLabel;
+    lblCreated: TKASCDEdit;
+    lblCreatedStr: TLabel;
     lblOctal: TLabel;
     lblAttrBitsStr: TLabel;
     lblAttrText: TLabel;
@@ -404,6 +406,13 @@ begin
     else
       lblLastModif.Caption := '';
 
+    lblCreated.Visible := fpCreationTime in SupportedProperties;
+    lblCreatedStr.Visible := fpCreationTime in SupportedProperties;
+    if fpCreationTime in SupportedProperties then
+      lblCreated.Caption := Properties[fpCreationTime].Format(FPropertyFormatter)
+    else
+      lblCreated.Caption := '';
+
     // Chown
     if isFileSystem and (fpLStat(PChar(UTF8ToSys(FullPath)), sb) = 0) then
     begin

+ 3 - 0
src/filesources/filesystem/ufilesystemfilesource.pas

@@ -332,6 +332,9 @@ begin
   begin
 {$IF DEFINED(UNIX)}
     ChangeTimeProperty := TFileChangeDateTimeProperty.Create(DCBasicTypes.TFileTime(pSearchRecord^.PlatformTime));
+    {$IF DEFINED(DARWIN)}
+    CreationTimeProperty := TFileCreationDateTimeProperty.Create(DCBasicTypes.TFileTime(pSearchRecord^.FindData.st_birthtime));
+    {$ENDIF}
 {$ELSE}
     CreationTimeProperty := TFileCreationDateTimeProperty.Create(DCBasicTypes.TFileTime(pSearchRecord^.PlatformTime));
 {$ENDIF}

+ 3 - 3
src/platform/ufindex.pas

@@ -3,7 +3,7 @@
     -------------------------------------------------------------------------
     This unit contains UTF-8 versions of Find(First, Next, Close) functions
 
-    Copyright (C) 2006-2020 Alexander Koblov ([email protected])
+    Copyright (C) 2006-2023 Alexander Koblov ([email protected])
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -69,7 +69,7 @@ type
     property LastAccessTime: TFileTime read FindData.ftLastAccessTime;
 {$ELSE}
     FindHandle : Pointer;
-    FindData : BaseUnix.Stat;
+    FindData : TDCStat;
     property PlatformTime: TUnixTime read FindData.st_ctime;
     property LastAccessTime: TUnixTime read FindData.st_atime;
 {$ENDIF}
@@ -122,7 +122,7 @@ begin
   if UnixFindHandle = nil then Exit;
   if (UnixFindHandle^.Mask = nil) or UnixFindHandle^.Mask.Matches(SearchRec.Name) then
   begin
-    if fpLStat(UTF8ToSys(UnixFindHandle^.FindPath + SearchRec.Name), @SearchRec.FindData) >= 0 then
+    if DC_fpLStat(UTF8ToSys(UnixFindHandle^.FindPath + SearchRec.Name), SearchRec.FindData) >= 0 then
     begin
       with SearchRec.FindData do
       begin