From 9c5c921b20e81c13326f30620ea6ae7203e23256 Mon Sep 17 00:00:00 2001 From: da3dsoul Date: Mon, 20 Nov 2023 18:10:43 -0500 Subject: [PATCH] Missed a spot --- .../RecoveringFileSystemWatcher.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Shoko.Server/Utilities/FileSystemWatcher/RecoveringFileSystemWatcher.cs b/Shoko.Server/Utilities/FileSystemWatcher/RecoveringFileSystemWatcher.cs index 84648a709..f81631e83 100644 --- a/Shoko.Server/Utilities/FileSystemWatcher/RecoveringFileSystemWatcher.cs +++ b/Shoko.Server/Utilities/FileSystemWatcher/RecoveringFileSystemWatcher.cs @@ -359,9 +359,7 @@ private long CanAccessFile(string fileName, ref Exception e) var accessType = Options.FileAccessMode; try { - using var fs = File.Open(fileName, FileMode.Open, accessType, FileShare.ReadWrite); - var size = fs.Seek(0, SeekOrigin.End); - return size; + return GetFileSize(fileName, accessType); } catch (IOException) { @@ -377,7 +375,7 @@ private long CanAccessFile(string fileName, ref Exception e) if (info.IsReadOnly) info.IsReadOnly = false; // check to see if it stuck. On linux, we can't just WinAPI hack our way out, so don't recurse in that case, anyway - if (!new FileInfo(fileName).IsReadOnly && !Utils.IsRunningOnLinuxOrMac()) return CanAccessFile(fileName, ref e); + if (!new FileInfo(fileName).IsReadOnly && !Utils.IsRunningOnLinuxOrMac()) return GetFileSize(fileName, accessType); } catch { @@ -389,6 +387,13 @@ private long CanAccessFile(string fileName, ref Exception e) } } + private static long GetFileSize(string fileName, FileAccess accessType) + { + using var fs = File.Open(fileName, FileMode.Open, accessType, FileShare.ReadWrite); + var size = fs.Seek(0, SeekOrigin.End); + return size; + } + //Used to check if file has been modified within the last X seconds. private bool FileModified(string fileName, int seconds, ref long lastFileSize, ref Exception e) {