@@ -726,35 +726,75 @@ private static FileMetadata GetFileMetadataOSX(string filePath)
726726 }
727727 }
728728
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 ;
735775
736776 public static FileAttributes OSXConvertStatModeToAttributes ( int st_mode , ReadOnlySpan < char > fileName )
737777 {
738778 FileAttributes attributes = FileAttributes . None ;
739779
740780 // File type determination
741- if ( ( st_mode & OSX_IFDIR ) == OSX_IFDIR )
781+ if ( OSXIsDirectory ( st_mode ) )
742782 {
743783 attributes |= FileAttributes . Directory ;
744784 }
745- else if ( ( st_mode & OSX_IFREG ) == OSX_IFREG )
785+ else if ( OSXIsRegularFile ( st_mode ) )
746786 {
747- attributes |= FileAttributes . Normal ;
787+ attributes |= FileAttributes . Normal ; // Used for symbolic links
748788 }
749- else if ( ( st_mode & OSX_IfLNK ) == OSX_IfLNK )
789+ else if ( OSXIsSymbolicLink ( st_mode ) )
750790 {
751- attributes |= FileAttributes . ReparsePoint ; // Symbolic links in Unix can be mapped to ReparsePoint in Windows
791+ attributes |= FileAttributes . ReparsePoint ; // Used for symbolic links
752792 }
753793
754794 // 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 )
756796 {
757- attributes |= FileAttributes . ReadOnly ;
797+ attributes |= FileAttributes . ReadOnly ; // If the owner has no read permission, mark it as read-only
758798 }
759799
760800 // Hidden file detection (Unix files that start with '.' are treated as hidden)
@@ -763,16 +803,18 @@ public static FileAttributes OSXConvertStatModeToAttributes(int st_mode, ReadOnl
763803 attributes |= FileAttributes . Hidden ;
764804 }
765805
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-
772806 return attributes ;
773807 }
774808
809+ public const int OSX_DT_UNKNOWN = 0 ;
810+ public const int OSX_DT_FIFO = 1 ;
811+ public const int OSX_DT_CHR = 2 ;
775812 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 ;
776818
777819 public const int DARWIN_MAXPATHLEN = 1024 ;
778820
@@ -799,7 +841,7 @@ public bool ShouldIgnore(string pattern, out bool result)
799841 result = ! FileSystemSearcher . IsMatch ( MemoryMarshal . CreateReadOnlySpanFromNullTerminated ( p ) , pattern , StringComparison . CurrentCulture ) ;
800842 }
801843
802- if ( d_type == DT_DIR )
844+ if ( d_type == OSX_DT_DIR )
803845 {
804846 return false ;
805847 }
0 commit comments