E2: motore delle copie esterne (porta, destinazioni, piano, copia)
Prima metà della tappa E2 «Copie esterne» (#58), parte Core e Data: - porta del lavoro lungo: importazione, copia e ricostruzione mai insieme; - radice /esporta in Docker con mountinfo, controllo delle cartelle con il file di prova, destinazioni con «Esporta questo account» acceso se Alberto non ha mai scelto (decisione del 27/11/2026); - filtro «Copie», segni delle tessere e conteggi dell'account sui soli file dovuti (D3); - percorsi «Come la libreria», segmento dell'account nella cartella generale, 240 caratteri, storia in evidenza; - piano di «Copia in…», un lavoro per destinazione, copia in .part con SHA-256 riletto dal disco, nome libero, mai sovrascrivere, adozione per percorso, pausa della destinazione su prova, spazio e FAT32, attesa fuori dalle sessioni del motore, ripresa e recupero; - .part rimossi solo nelle cartelle degli elementi di lavori non finiti; - «Tolto» e «Superato» (agganci in importazione, scaricamenti, doppioni e ricostruzione), mai ricopiati da soli; - rapporti e testi in italiano, prove del lavoro di copia. Interfaccia, API e composizione restano alla parte successiva. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
213b89a618
commit
a112c92893
41 files changed
+5370
-27
No files matched your search
@@ -0,0 +1,114 @@
|
||||
namespace Febe.Core.Library;
|
||||
|
||||
/// <summary>
|
||||
/// One line of <c>/proc/self/mountinfo</c> (proc(5)): unlike <c>/proc/self/mounts</c> it says which folder of its file
|
||||
/// system a mount shows (<see cref="Root"/>: <c>/</c> when the mount is the root of that file system) and gives the exact
|
||||
/// mount point, which the export needs for <c>/esporta</c> (spec §4.10, §11).
|
||||
/// </summary>
|
||||
/// <param name="Id">Mount id.</param>
|
||||
/// <param name="ParentId">Id of the parent mount.</param>
|
||||
/// <param name="Root">Folder of the file system shown at the mount point (<c>/</c>: its root).</param>
|
||||
/// <param name="MountPoint">Where it is mounted, unescaped.</param>
|
||||
/// <param name="Options">Per-mount options (<c>rw</c>, <c>ro</c>, <c>noatime</c>…).</param>
|
||||
/// <param name="FileSystemType">File system type (<c>ext4</c>, <c>vfat</c>, <c>cifs</c>…).</param>
|
||||
/// <param name="Source">Mount source (<c>/dev/sdb1</c>, <c>//server/share</c>…), unescaped.</param>
|
||||
public sealed record MountInfoEntry(int Id, int ParentId, string Root, string MountPoint, IReadOnlyList<string> Options, string FileSystemType, string Source)
|
||||
{
|
||||
/// <summary>The mount is read-only (<c>ro</c>, as for a Docker volume mounted with <c>:ro</c>).</summary>
|
||||
public bool ReadOnly => Options.Contains("ro", StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>Reads <c>/proc/self/mountinfo</c>.</summary>
|
||||
public static class MountInfoTable
|
||||
{
|
||||
private const string MountInfoPath = "/proc/self/mountinfo";
|
||||
|
||||
/// <summary>
|
||||
/// Parses the content of <c>/proc/self/mountinfo</c>: fields 0-5, then optional fields up to the separator «-», then
|
||||
/// file system type and source. Malformed lines are skipped; nothing throws.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<MountInfoEntry> Parse(string content)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(content);
|
||||
var entries = new List<MountInfoEntry>();
|
||||
foreach (var raw in content.Split('\n'))
|
||||
{
|
||||
var fields = raw.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (fields.Length < 9
|
||||
|| !int.TryParse(fields[0], System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out var id)
|
||||
|| !int.TryParse(fields[1], System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out var parent))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var separator = Array.IndexOf(fields, "-", 6);
|
||||
if (separator < 0 || separator + 2 >= fields.Length)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var root = MountTable.Unescape(fields[3]);
|
||||
var point = MountTable.Unescape(fields[4]);
|
||||
if (!root.StartsWith('/') || !point.StartsWith('/'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
entries.Add(new MountInfoEntry(
|
||||
id,
|
||||
parent,
|
||||
root,
|
||||
point,
|
||||
fields[5].Split(',', StringSplitOptions.RemoveEmptyEntries),
|
||||
fields[separator + 1],
|
||||
MountTable.Unescape(fields[separator + 2])));
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mount that holds a path: the longest mount point that is the path itself or one of its parents (ordinal
|
||||
/// comparison; a later mount over the same point wins, as the kernel shows the last one). Null when none matches.
|
||||
/// </summary>
|
||||
public static MountInfoEntry? FindContaining(IReadOnlyList<MountInfoEntry> mounts, string fullPath)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(mounts);
|
||||
ArgumentNullException.ThrowIfNull(fullPath);
|
||||
var path = fullPath.Length > 1 ? fullPath.TrimEnd('/') : fullPath;
|
||||
MountInfoEntry? best = null;
|
||||
var bestLength = -1;
|
||||
foreach (var mount in mounts)
|
||||
{
|
||||
var point = mount.MountPoint.Length > 1 ? mount.MountPoint.TrimEnd('/') : mount.MountPoint;
|
||||
var contains = point == "/"
|
||||
|| string.Equals(path, point, StringComparison.Ordinal)
|
||||
|| path.StartsWith(point + "/", StringComparison.Ordinal);
|
||||
if (contains && point.Length >= bestLength)
|
||||
{
|
||||
best = mount;
|
||||
bestLength = point.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>The content of <c>/proc/self/mountinfo</c> on Linux; null elsewhere or when it cannot be read.</summary>
|
||||
public static string? ReadProcSelf()
|
||||
{
|
||||
if (!OperatingSystem.IsLinux())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return File.Exists(MountInfoPath) ? File.ReadAllText(MountInfoPath) : null;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user