@@ -726,35 +726,75 @@ private static FileMetadata GetFileMetadataOSX(string filePath)
726
726
}
727
727
}
728
728
729
- private const int OSX_IFDIR = 0x4000 ; // Directory
730
- private const int OSX_IFREG = 0x8000 ; // Regular file
731
- private const int OSX_IfLNK = 0xA000 ; // Symbolic link (Unix)
732
- private const int OSX_IRUSR = 0x0100 ; // Owner read permission
733
- private const int OSX_IWUSR = 0x0080 ; // Owner write permission
734
- private const int OSX_IXUSR = 0x0040 ; // Owner execute permission
729
+ public const int OSX_S_IFMT = 0xF000 ; // type of file
730
+ public const int OSX_S_IFIFO = 0x1000 ; // named pipe (fifo)
731
+ public const int OSX_S_IFCHR = 0x2000 ; // character special
732
+ public const int OSX_S_IFDIR = 0x4000 ; // directory
733
+ public const int OSX_S_IFBLK = 0x6000 ; // block special
734
+ public const int OSX_S_IFREG = 0x8000 ; // regular file
735
+ public const int OSX_S_IFLNK = 0xA000 ; // symbolic link
736
+ public const int OSX_S_IFSOCK = 0xC000 ; // socket
737
+ public const int OSX_S_IFWHT = 0xE000 ; // whiteout
738
+
739
+ public const int OSX_S_ISUID = 0x0800 ; // set user ID on execution
740
+ public const int OSX_S_ISGID = 0x0400 ; // set group ID on execution
741
+ public const int OSX_S_ISVTX = 0x0200 ; // save swapped text even after use
742
+
743
+ public const int OSX_S_IRUSR = 0x0100 ; // read permission, owner
744
+ public const int OSX_S_IWUSR = 0x0080 ; // write permission, owner
745
+ public const int OSX_S_IXUSR = 0x0040 ; // execute/search permission, owner
746
+
747
+ public static bool OSXIsBlockSpecial ( int mode ) => ( mode & OSX_S_IFMT ) == OSX_S_IFBLK ;
748
+
749
+ public static bool OSXIsCharSpecial ( int mode ) => ( mode & OSX_S_IFMT ) == OSX_S_IFCHR ;
750
+
751
+ public static bool OSXIsDirectory ( int mode ) => ( mode & OSX_S_IFMT ) == S_IFDIR ;
752
+
753
+ public static bool OSXIsFifo ( int mode ) => ( mode & OSX_S_IFMT ) == OSX_S_IFIFO ;
754
+
755
+ public static bool OSXIsRegularFile ( int mode ) => ( mode & OSX_S_IFMT ) == S_IFREG ;
756
+
757
+ public static bool OSXIsSymbolicLink ( int mode ) => ( mode & OSX_S_IFMT ) == S_IFLNK ;
758
+
759
+ public static bool OSXIsSocket ( int mode ) => ( mode & OSX_S_IFMT ) == OSX_S_IFSOCK ;
760
+
761
+ public static bool OSXIsWhiteout ( int mode ) => ( mode & OSX_S_IFMT ) == OSX_S_IFWHT ;
762
+
763
+ // Helper methods to check permissions
764
+ public static bool OSXIsSetUserID ( int mode ) => ( mode & OSX_S_ISUID ) != 0 ;
765
+
766
+ public static bool OSXIsSetGroupID ( int mode ) => ( mode & OSX_S_ISGID ) != 0 ;
767
+
768
+ public static bool OSXIsStickyBitSet ( int mode ) => ( mode & OSX_S_ISVTX ) != 0 ;
769
+
770
+ public static bool OSXCanRead ( int mode ) => ( mode & S_IRUSR ) != 0 ;
771
+
772
+ public static bool OSXCanWrite ( int mode ) => ( mode & S_IWUSR ) != 0 ;
773
+
774
+ public static bool OSXCanExecute ( int mode ) => ( mode & S_IXUSR ) != 0 ;
735
775
736
776
public static FileAttributes OSXConvertStatModeToAttributes ( int st_mode , ReadOnlySpan < char > fileName )
737
777
{
738
778
FileAttributes attributes = FileAttributes . None ;
739
779
740
780
// File type determination
741
- if ( ( st_mode & OSX_IFDIR ) == OSX_IFDIR )
781
+ if ( OSXIsDirectory ( st_mode ) )
742
782
{
743
783
attributes |= FileAttributes . Directory ;
744
784
}
745
- else if ( ( st_mode & OSX_IFREG ) == OSX_IFREG )
785
+ else if ( OSXIsRegularFile ( st_mode ) )
746
786
{
747
- attributes |= FileAttributes . Normal ;
787
+ attributes |= FileAttributes . Normal ; // Used for symbolic links
748
788
}
749
- else if ( ( st_mode & OSX_IfLNK ) == OSX_IfLNK )
789
+ else if ( OSXIsSymbolicLink ( st_mode ) )
750
790
{
751
- attributes |= FileAttributes . ReparsePoint ; // Symbolic links in Unix can be mapped to ReparsePoint in Windows
791
+ attributes |= FileAttributes . ReparsePoint ; // Used for symbolic links
752
792
}
753
793
754
794
// Permission handling - If no write permission for the owner, mark as ReadOnly
755
- if ( ( st_mode & OSX_IRUSR ) == 0 )
795
+ if ( ( st_mode & OSX_S_IRUSR ) == 0 )
756
796
{
757
- attributes |= FileAttributes . ReadOnly ;
797
+ attributes |= FileAttributes . ReadOnly ; // If the owner has no read permission, mark it as read-only
758
798
}
759
799
760
800
// Hidden file detection (Unix files that start with '.' are treated as hidden)
@@ -763,16 +803,18 @@ public static FileAttributes OSXConvertStatModeToAttributes(int st_mode, ReadOnl
763
803
attributes |= FileAttributes . Hidden ;
764
804
}
765
805
766
- // Add other attributes as necessary, but keep in mind Unix-like systems may not have equivalents for:
767
- // - FileAttributes.Compressed
768
- // - FileAttributes.Encrypted
769
- // - FileAttributes.Offline
770
- // - FileAttributes.NotContentIndexed
771
-
772
806
return attributes ;
773
807
}
774
808
809
+ public const int OSX_DT_UNKNOWN = 0 ;
810
+ public const int OSX_DT_FIFO = 1 ;
811
+ public const int OSX_DT_CHR = 2 ;
775
812
public const int OSX_DT_DIR = 4 ;
813
+ public const int OSX_DT_BLK = 6 ;
814
+ public const int OSX_DT_REG = 8 ;
815
+ public const int OSX_DT_LNK = 10 ;
816
+ public const int OSX_DT_SOCK = 12 ;
817
+ public const int OSX_DT_WHT = 14 ;
776
818
777
819
public const int DARWIN_MAXPATHLEN = 1024 ;
778
820
@@ -799,7 +841,7 @@ public bool ShouldIgnore(string pattern, out bool result)
799
841
result = ! FileSystemSearcher . IsMatch ( MemoryMarshal . CreateReadOnlySpanFromNullTerminated ( p ) , pattern , StringComparison . CurrentCulture ) ;
800
842
}
801
843
802
- if ( d_type == DT_DIR )
844
+ if ( d_type == OSX_DT_DIR )
803
845
{
804
846
return false ;
805
847
}
0 commit comments