@@ -76,6 +76,16 @@ public FSWatcher(string directory, string filter)
7676
7777 private bool IsFileSymlink ( string path )
7878 {
79+ if ( Environment . OSVersion . Platform == PlatformID . Unix )
80+ {
81+ int result = Syscall . lstat ( path , out Stat buff ) ;
82+
83+ if ( result > 0 )
84+ {
85+ return ( buff . st_mode & FilePermissions . S_IFMT ) == FilePermissions . S_IFLNK ;
86+ }
87+ }
88+
7989 return ( File . GetAttributes ( path ) & FileAttributes . ReparsePoint ) > 0 ;
8090 }
8191
@@ -86,11 +96,13 @@ private bool IsFileSymlink(string path)
8696 private void LoadWatcherSymlink ( string path )
8797 {
8898 StringBuilder str = StringPool . Take ( ) ;
99+ str . Capacity = 4096 ;
100+ int count = 0 ;
89101 try
90102 {
91- int count = Syscall . readlink ( path , str ) ;
103+ count = Syscall . readlink ( path , str ) ;
92104
93- if ( count == - 1 )
105+ if ( count < 0 )
94106 {
95107 Errno err = Stdlib . GetLastError ( ) ;
96108
@@ -104,17 +116,20 @@ private void LoadWatcherSymlink(string path)
104116 }
105117 }
106118
107- string realPath = str . ToString ( 0 , str . Length ) ;
108-
109- #if DEBUG
110- if ( str . Length != count )
119+ if ( count == 0 )
111120 {
112- Interface . Oxide . LogDebug ( $ "Path { path } returned a symlink at { realPath } but wrong length was reported | { count } != { str . Length } " ) ;
113- }
121+ #if DEBUG
122+ Interface . Oxide . LogError ( $ "Unable to read symbolic link: { path } " ) ;
114123#endif
124+ return ;
125+ }
115126
127+ string realPath = str . ToString ( 0 , count ) ;
116128 string realDirName = Path . GetDirectoryName ( realPath ) ;
117129 string realFileName = Path . GetFileName ( realPath ) ;
130+ #if DEBUG
131+ Interface . Oxide . LogDebug ( $ "Read symbolic link: { realPath } | Original: { path } ") ;
132+ #endif
118133
119134 void symlinkTarget_Changed ( object sender , FileSystemEventArgs e ) => watcher_Changed ( sender , e ) ;
120135
@@ -128,6 +143,13 @@ private void LoadWatcherSymlink(string path)
128143 watcher . IncludeSubdirectories = false ;
129144 watcher . EnableRaisingEvents = true ;
130145 }
146+ catch ( Exception e )
147+ {
148+ #if DEBUG
149+ Interface . Oxide . LogDebug ( $ "Failed to process symlink | Original: ({ path . Length } ) { path } | Link: ({ str . Length } ) { str } ") ;
150+ Interface . Oxide . LogException ( e . Message , e ) ;
151+ #endif
152+ }
131153 finally
132154 {
133155 StringPool . Return ( str ) ;
0 commit comments