Added comments, clean-up

This commit is contained in:
cake
2025-10-29 22:54:50 +01:00
parent c37e3badf1
commit 7c4d0fd5e9
4 changed files with 45 additions and 39 deletions

View File

@@ -1,10 +1,8 @@
using LightlessSync.LightlessConfiguration;
using LightlessSync.Services;
using LightlessSync.Utils;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Channels;
using static LightlessSync.Utils.FileSystemHelper;
@@ -106,6 +104,7 @@ public sealed class FileCompactor : IDisposable
try
{
long blocks = RunStatGetBlocks(fileInfo.FullName);
//st_blocks are always calculated in 512-byte units, hence we use 512L
return blocks * 512L;
}
catch (Exception ex)
@@ -161,17 +160,17 @@ public sealed class FileCompactor : IDisposable
[StructLayout(LayoutKind.Sequential)]
private struct Statvfs
{
public ulong f_bsize;
public ulong f_frsize;
public ulong f_blocks;
public ulong f_bfree;
public ulong f_bavail;
public ulong f_files;
public ulong f_ffree;
public ulong f_favail;
public ulong f_fsid;
public ulong f_flag;
public ulong f_namemax;
public ulong f_bsize; /* Filesystem block size */
public ulong f_frsize; /* Fragment size */
public ulong f_blocks; /* Size of fs in f_frsize units */
public ulong f_bfree; /* Number of free blocks */
public ulong f_bavail; /* Number of free blocks for unprivileged users */
public ulong f_files; /* Number of inodes */
public ulong f_ffree; /* Number of free inodes */
public ulong f_favail; /* Number of free inodes for unprivileged users */
public ulong f_fsid; /* Filesystem ID */
public ulong f_flag; /* Mount flags */
public ulong f_namemax; /* Maximum filename length */
}
private static int GetLinuxBlockSize(string path)
@@ -182,6 +181,7 @@ public sealed class FileCompactor : IDisposable
if (result != 0)
return -1;
//return fragment size of linux
return (int)buf.f_frsize;
}
catch
@@ -346,9 +346,7 @@ public sealed class FileCompactor : IDisposable
var mountOptions = GetMountOptionsForPath(path);
if (mountOptions.Contains("compress", StringComparison.OrdinalIgnoreCase))
{
_logger.LogWarning(
"Cannot safely decompress {file}: filesystem mounted with compression ({opts}). " +
"Remount with 'compress=no' before running decompression.", path, mountOptions);
_logger.LogWarning("Cannot safely decompress {file}: filesystem mounted with compression ({opts}). Remount with 'compress=no' before running decompression.", path, mountOptions);
return;
}
@@ -369,6 +367,7 @@ public sealed class FileCompactor : IDisposable
return;
}
//End stream of process to read the files
var stdout = proc.StandardOutput.ReadToEnd();
var stderr = proc.StandardError.ReadToEnd();
proc.WaitForExit();