From bf139c128b75b8d744864cb9b574c74c91e65ad6 Mon Sep 17 00:00:00 2001 From: cake Date: Thu, 30 Oct 2025 03:11:38 +0100 Subject: [PATCH] Added fail safes in compact of WOF incase --- LightlessSync/FileCache/FileCompactor.cs | 32 ++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/LightlessSync/FileCache/FileCompactor.cs b/LightlessSync/FileCache/FileCompactor.cs index 60cc78e..2e32a3e 100644 --- a/LightlessSync/FileCache/FileCompactor.cs +++ b/LightlessSync/FileCache/FileCompactor.cs @@ -138,7 +138,7 @@ public sealed class FileCompactor : IDisposable _compactionCts.Cancel(); try { - if (!_compactionWorker.Wait(TimeSpan.FromSeconds(5))) + if (!_compactionWorker.Wait(TimeSpan.FromSeconds(5), _compactionCts.Token)) { _logger.LogDebug("Compaction worker did not shut down within timeout"); } @@ -463,10 +463,32 @@ public sealed class FileCompactor : IDisposable private static bool IsWOFCompactedFile(string filePath) { - uint buf = 8; - _ = WofIsExternalFile(filePath, out int isExtFile, out uint _, out var info, ref buf); - if (isExtFile == 0) return false; - return info.Algorithm == CompressionAlgorithm.XPRESS8K; + try + { + uint buf = (uint)Marshal.SizeOf(); + int result = WofIsExternalFile(filePath, out int isExternal, out uint _, out var info, ref buf); + + if (result != 0 || isExternal == 0) + return false; + + return info.Algorithm == CompressionAlgorithm.XPRESS8K || info.Algorithm == CompressionAlgorithm.XPRESS4K + || info.Algorithm == CompressionAlgorithm.XPRESS16K || info.Algorithm == CompressionAlgorithm.LZX; + } + catch (DllNotFoundException) + { + // WofUtil.dll not available + return false; + } + catch (EntryPointNotFoundException) + { + // Running under Wine or non-NTFS systems + return false; + } + catch (Exception) + { + // Exception happened + return false; + } } private bool IsBtrfsCompressedFile(string path)