Refactored a bit, added comments on the file systems.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using LightlessSync.LightlessConfiguration;
|
using LightlessSync.LightlessConfiguration;
|
||||||
using LightlessSync.Services;
|
using LightlessSync.Services;
|
||||||
|
using LightlessSync.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -181,7 +182,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
if (result != 0)
|
if (result != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
//return fragment size of linux
|
//return fragment size of Linux file system
|
||||||
return (int)buf.f_frsize;
|
return (int)buf.f_frsize;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -413,12 +414,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !_dalamudUtilService.IsWine)
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !_dalamudUtilService.IsWine)
|
||||||
{
|
{
|
||||||
int result = GetDiskFreeSpaceW(
|
int result = GetDiskFreeSpaceW(root, out uint sectorsPerCluster, out uint bytesPerSector, out _, out _);
|
||||||
root,
|
|
||||||
out uint sectorsPerCluster,
|
|
||||||
out uint bytesPerSector,
|
|
||||||
out _,
|
|
||||||
out _);
|
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
@@ -495,12 +491,10 @@ public sealed class FileCompactor : IDisposable
|
|||||||
string output = proc.StandardOutput.ReadToEnd();
|
string output = proc.StandardOutput.ReadToEnd();
|
||||||
proc.WaitForExit();
|
proc.WaitForExit();
|
||||||
|
|
||||||
if (output.Contains("flags: compressed", StringComparison.OrdinalIgnoreCase))
|
bool compressed = output.Contains("flags: compressed", StringComparison.OrdinalIgnoreCase);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
_logger.LogTrace("Btrfs compression check for {file}: {compressed}", path, compressed);
|
||||||
|
return compressed;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
private struct WOF_FILE_COMPRESSION_INFO_V1
|
||||||
{
|
{
|
||||||
public CompressionAlgorithm Algorithm;
|
public CompressionAlgorithm Algorithm;
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ namespace LightlessSync.Utils
|
|||||||
public enum FilesystemType
|
public enum FilesystemType
|
||||||
{
|
{
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
NTFS, // Compressable
|
NTFS, // Compressable on file level
|
||||||
Btrfs, // Compressable
|
Btrfs, // Compressable on file level
|
||||||
Ext4,
|
Ext4, // Uncompressable
|
||||||
Xfs,
|
Xfs, // Uncompressable
|
||||||
Apfs,
|
Apfs, // Compressable on OS
|
||||||
HfsPlus,
|
HfsPlus, // Compressable on OS
|
||||||
Fat,
|
Fat, // Uncompressable
|
||||||
Exfat,
|
Exfat, // Uncompressable
|
||||||
Zfs // Compressable
|
Zfs // Compressable, not on file level
|
||||||
}
|
}
|
||||||
|
|
||||||
private const string _mountPath = "/proc/mounts";
|
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)
|
private static FilesystemType GetLinuxFilesystemType(string filePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user