Refactored a bit, added comments on the file systems.

This commit is contained in:
cake
2025-10-30 03:05:53 +01:00
parent 7c4d0fd5e9
commit b3cc41382f
2 changed files with 49 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
using LightlessSync.LightlessConfiguration;
using LightlessSync.Services;
using LightlessSync.Utils;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Diagnostics;
@@ -181,7 +182,7 @@ public sealed class FileCompactor : IDisposable
if (result != 0)
return -1;
//return fragment size of linux
//return fragment size of Linux file system
return (int)buf.f_frsize;
}
catch
@@ -413,12 +414,7 @@ public sealed class FileCompactor : IDisposable
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !_dalamudUtilService.IsWine)
{
int result = GetDiskFreeSpaceW(
root,
out uint sectorsPerCluster,
out uint bytesPerSector,
out _,
out _);
int result = GetDiskFreeSpaceW(root, out uint sectorsPerCluster, out uint bytesPerSector, out _, out _);
if (result == 0)
{
@@ -495,12 +491,10 @@ public sealed class FileCompactor : IDisposable
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
if (output.Contains("flags: compressed", StringComparison.OrdinalIgnoreCase))
{
return true;
}
bool compressed = output.Contains("flags: compressed", StringComparison.OrdinalIgnoreCase);
return false;
_logger.LogTrace("Btrfs compression check for {file}: {compressed}", path, compressed);
return compressed;
}
catch (Exception ex)
{
@@ -586,41 +580,6 @@ public sealed class FileCompactor : IDisposable
}
}
private string GetMountOptionsForPath(string path)
{
try
{
var fullPath = Path.GetFullPath(path);
var mounts = File.ReadAllLines("/proc/mounts");
string bestMount = string.Empty;
string mountOptions = string.Empty;
foreach (var line in mounts)
{
var parts = line.Split(' ');
if (parts.Length < 4) continue;
var mountPoint = parts[1].Replace("\\040", " ", StringComparison.Ordinal);
string normalized;
try { normalized = Path.GetFullPath(mountPoint); }
catch { normalized = mountPoint; }
if (fullPath.StartsWith(normalized, StringComparison.Ordinal) &&
normalized.Length > bestMount.Length)
{
bestMount = normalized;
mountOptions = parts[3];
}
}
return mountOptions;
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Failed to get mount options for {path}", path);
return string.Empty;
}
}
private struct WOF_FILE_COMPRESSION_INFO_V1
{
public CompressionAlgorithm Algorithm;

View File

@@ -8,15 +8,15 @@ namespace LightlessSync.Utils
public enum FilesystemType
{
Unknown = 0,
NTFS, // Compressable
Btrfs, // Compressable
Ext4,
Xfs,
Apfs,
HfsPlus,
Fat,
Exfat,
Zfs // Compressable
NTFS, // Compressable on file level
Btrfs, // Compressable on file level
Ext4, // Uncompressable
Xfs, // Uncompressable
Apfs, // Compressable on OS
HfsPlus, // Compressable on OS
Fat, // Uncompressable
Exfat, // Uncompressable
Zfs // Compressable, not on file level
}
private const string _mountPath = "/proc/mounts";
@@ -105,6 +105,40 @@ namespace LightlessSync.Utils
}
}
public static string GetMountOptionsForPath(string path)
{
try
{
var fullPath = Path.GetFullPath(path);
var mounts = File.ReadAllLines("/proc/mounts");
string bestMount = string.Empty;
string mountOptions = string.Empty;
foreach (var line in mounts)
{
var parts = line.Split(' ');
if (parts.Length < 4) continue;
var mountPoint = parts[1].Replace("\\040", " ", StringComparison.Ordinal);
string normalized;
try { normalized = Path.GetFullPath(mountPoint); }
catch { normalized = mountPoint; }
if (fullPath.StartsWith(normalized, StringComparison.Ordinal) &&
normalized.Length > bestMount.Length)
{
bestMount = normalized;
mountOptions = parts[3];
}
}
return mountOptions;
}
catch (Exception ex)
{
return string.Empty;
}
}
private static FilesystemType GetLinuxFilesystemType(string filePath)
{
try