Skip to content

Commit a5db8fe

Browse files
committed
Revert "Add a unix specific check for IsSymbolicLink"
This reverts commit d5394ae.
1 parent 05fa88e commit a5db8fe

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/Plugins/Watchers/FSWatcher.cs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ 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-
8979
return (File.GetAttributes(path) & FileAttributes.ReparsePoint) > 0;
9080
}
9181

@@ -96,13 +86,11 @@ private bool IsFileSymlink(string path)
9686
private void LoadWatcherSymlink(string path)
9787
{
9888
StringBuilder str = StringPool.Take();
99-
str.Capacity = 4096;
100-
int count = 0;
10189
try
10290
{
103-
count = Syscall.readlink(path, str);
91+
int count = Syscall.readlink(path, str);
10492

105-
if (count < 0)
93+
if (count == -1)
10694
{
10795
Errno err = Stdlib.GetLastError();
10896

@@ -116,20 +104,17 @@ private void LoadWatcherSymlink(string path)
116104
}
117105
}
118106

119-
if (count == 0)
120-
{
107+
string realPath = str.ToString(0, str.Length);
108+
121109
#if DEBUG
122-
Interface.Oxide.LogError($"Unable to read symbolic link: {path}");
123-
#endif
124-
return;
110+
if (str.Length != count)
111+
{
112+
Interface.Oxide.LogDebug($"Path {path} returned a symlink at {realPath} but wrong length was reported | {count} != {str.Length}");
125113
}
114+
#endif
126115

127-
string realPath = str.ToString(0, count);
128116
string realDirName = Path.GetDirectoryName(realPath);
129117
string realFileName = Path.GetFileName(realPath);
130-
#if DEBUG
131-
Interface.Oxide.LogDebug($"Read symbolic link: {realPath} | Original: {path}");
132-
#endif
133118

134119
void symlinkTarget_Changed(object sender, FileSystemEventArgs e) => watcher_Changed(sender, e);
135120

@@ -143,13 +128,6 @@ private void LoadWatcherSymlink(string path)
143128
watcher.IncludeSubdirectories = false;
144129
watcher.EnableRaisingEvents = true;
145130
}
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-
}
153131
finally
154132
{
155133
StringPool.Return(str);

0 commit comments

Comments
 (0)