Integrazione 0.1.1: unione di correzione/prove-su-windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/decisioni.md
This commit is contained in:
commit
5dc9b4c6ae
7 files changed
+105
-16
No files matched your search
@@ -15,7 +15,9 @@ public sealed class HostingTests
|
||||
var args = ChromiumCommandLine.Build(Options, new ChromiumLaunchOptions());
|
||||
|
||||
CollectionAssert.Contains(args.ToList(), "--remote-debugging-port=9333");
|
||||
CollectionAssert.Contains(args.ToList(), "--user-data-dir=/tmp/febe-profilo");
|
||||
|
||||
// The profile reaches Chromium as a full path: «/tmp/febe-profilo» on Linux, rooted on the current drive on Windows.
|
||||
CollectionAssert.Contains(args.ToList(), $"--user-data-dir={Path.GetFullPath(Options.ProfileDirectory)}");
|
||||
CollectionAssert.Contains(args.ToList(), "--no-first-run");
|
||||
CollectionAssert.Contains(args.ToList(), "--no-default-browser-check");
|
||||
CollectionAssert.Contains(args.ToList(), "--window-size=1280,900");
|
||||
|
||||
@@ -112,10 +112,10 @@ public sealed partial class InstallerTests
|
||||
StringAssert.Contains(text, "100 * 1024 * 1024");
|
||||
Assert.DoesNotContain("\r\n", text, "Unix line ends: bash would choke on CR");
|
||||
|
||||
var bash = FindOnPath("bash");
|
||||
var bash = FindBash();
|
||||
if (bash is null)
|
||||
{
|
||||
return;
|
||||
Assert.Inconclusive("Manca bash (su Windows: Git Bash): la prova della sintassi di costruisci.sh si salta.");
|
||||
}
|
||||
|
||||
using var process = Process.Start(new ProcessStartInfo(bash, ["-n", script]) { RedirectStandardError = true })!;
|
||||
@@ -124,21 +124,69 @@ public sealed partial class InstallerTests
|
||||
Assert.AreEqual(0, process.ExitCode, errors);
|
||||
}
|
||||
|
||||
private static string? FindOnPath(string name)
|
||||
private static string? FindOnPath(string name) => OnPath(name).FirstOrDefault();
|
||||
|
||||
/// <summary>
|
||||
/// A bash that checks the script on this system. Elsewhere than Windows, the first on PATH. On Windows Git Bash
|
||||
/// first (next to git on PATH, then where its installer puts it), else any bash on PATH except the WSL launcher:
|
||||
/// <c>System32\bash.exe</c> and the <c>WindowsApps</c> alias start a Linux distribution, which may be missing
|
||||
/// («execvpe(/bin/bash) failed») and does not see the script by its Windows path.
|
||||
/// </summary>
|
||||
private static string? FindBash()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
return FindOnPath("bash");
|
||||
}
|
||||
|
||||
var roots = new List<string>();
|
||||
if (FindOnPath("git") is { } git)
|
||||
{
|
||||
// git.exe sits in <Git>\cmd, <Git>\bin or <Git>\mingw64\bin.
|
||||
for (var folder = Path.GetDirectoryName(git); folder is not null && roots.Count < 3; folder = Path.GetDirectoryName(folder))
|
||||
{
|
||||
roots.Add(folder);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var variable in new[] { "ProgramW6432", "ProgramFiles", "ProgramFiles(x86)" })
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable(variable) is { Length: > 0 } programs)
|
||||
{
|
||||
roots.Add(Path.Combine(programs, "Git"));
|
||||
}
|
||||
}
|
||||
|
||||
roots.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "Git"));
|
||||
var gitBash = roots
|
||||
.SelectMany(root => new[] { Path.Combine(root, "bin", "bash.exe"), Path.Combine(root, "usr", "bin", "bash.exe") })
|
||||
.FirstOrDefault(path => File.Exists(path) && !IsWslLauncher(path));
|
||||
return gitBash ?? OnPath("bash").FirstOrDefault(path => !IsWslLauncher(path));
|
||||
}
|
||||
|
||||
private static bool IsWslLauncher(string path)
|
||||
{
|
||||
var full = Path.GetFullPath(path);
|
||||
var windows = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
|
||||
return (windows.Length > 0 && full.StartsWith(Path.TrimEndingDirectorySeparator(windows) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
|| full.Contains(@"\Microsoft\WindowsApps\", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>Every file called <paramref name="name"/> on PATH, in order (on Windows only <c>.exe</c>: the others do not start).</summary>
|
||||
private static IEnumerable<string> OnPath(string name)
|
||||
{
|
||||
var candidates = OperatingSystem.IsWindows() ? new[] { name + ".exe" } : new[] { name, name + ".exe" };
|
||||
foreach (var folder in (Environment.GetEnvironmentVariable("PATH") ?? string.Empty).Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
foreach (var candidate in new[] { name, name + ".exe" })
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
var path = Path.Combine(folder, candidate);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
return path;
|
||||
yield return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^\s*(?:Delete|RMDir)(?:\s+/\w+)*\s+""(?<target>[^""]+)""", RegexOptions.Multiline)]
|
||||
|
||||
@@ -27,7 +27,8 @@ public sealed class ImportSourcesTests
|
||||
Assert.AreEqual(Path.Combine(root, "4K Stogram"), info.FullPath);
|
||||
Assert.IsTrue(info.ReadOnly, "Il volume /importa è in sola lettura.");
|
||||
Assert.IsFalse(info.CanMove);
|
||||
Assert.AreEqual(root + "/4K Stogram", info.DisplayPath);
|
||||
// Shown as in the container, with «/»: the same text as the root on Linux; on Windows the separators change too.
|
||||
Assert.AreEqual(LibraryLayout.ToStored(root) + "/4K Stogram", info.DisplayPath);
|
||||
|
||||
var outside = Assert.ThrowsExactly<ImportSourceException>(() => sources.Inspect(temp.Combine("fuori")));
|
||||
StringAssert.Contains(outside.Message, "sottocartella");
|
||||
|
||||
@@ -99,14 +99,23 @@ public sealed class StartupProblemTests
|
||||
[TestMethod]
|
||||
public async Task ADataFolderOnANetworkShareIsRefused()
|
||||
{
|
||||
// A share shows itself differently on the two systems: on Linux as a cifs mount in the mount table (injected
|
||||
// here), on Windows as a UNC path, recognised from its form before anything touches it. The Windows server name
|
||||
// ends in .invalid (RFC 6761): no machine answers to it, and nothing here looks it up.
|
||||
using var temp = new TempFolder("server-problemi");
|
||||
var data = temp.Combine("dati");
|
||||
var windows = OperatingSystem.IsWindows();
|
||||
var data = windows ? @"\\febe-prova.invalid\condivisa\dati" : temp.Combine("dati");
|
||||
var mounts = $"/dev/sda1 / ext4 rw 0 0\n//nas/condivisa {temp.Path} cifs rw 0 0\n";
|
||||
await using var server = await FebeServer.StartAsync(Options(temp), Hooks() with { DataFolderCheck = new DataFolderCheck(() => mounts) });
|
||||
await using var server = await FebeServer.StartAsync(Options(temp) with { DataFolder = data }, Hooks() with { DataFolderCheck = new DataFolderCheck(() => mounts) });
|
||||
var problem = server.Problems.Single();
|
||||
Assert.AreEqual(StartupChecks.DataOnNetwork, problem.Code);
|
||||
StringAssert.Contains(problem.Message, "cifs");
|
||||
Assert.IsFalse(Directory.Exists(Path.Combine(data, "registro")));
|
||||
StringAssert.Contains(problem.Message, windows ? "condivisione di rete" : "cifs");
|
||||
if (!windows)
|
||||
{
|
||||
// Nothing written in the Data folder (on Windows the share does not exist: looking would mean asking the network).
|
||||
Assert.IsFalse(Directory.Exists(Path.Combine(data, "registro")));
|
||||
}
|
||||
|
||||
using var client = Client(server);
|
||||
await AssertHealthAsync(client, HttpStatusCode.ServiceUnavailable, """{"stato":"problema"}""");
|
||||
}
|
||||
|
||||
@@ -63,13 +63,36 @@ internal sealed class TestLibrary : IAsyncDisposable
|
||||
await Db.DisposeAsync();
|
||||
foreach (var suffix in new[] { string.Empty, "-wal", "-shm" })
|
||||
{
|
||||
File.Delete(Data.Database + suffix);
|
||||
await DeleteClosedFileAsync(Data.Database + suffix);
|
||||
}
|
||||
|
||||
Db = await FebeDatabase.OpenAsync(Data.Root);
|
||||
Ingest = new LibraryIngest(Db, Layout, LibraryNaming.Default, Journal, Clock, Thumbnails, Index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a file Febe has already closed. On Windows a file still held open elsewhere cannot be deleted, and on one PC a
|
||||
/// database just closed was now and then held for a few milliseconds by something outside Febe (Restart Manager listed
|
||||
/// no process; probably the real-time antivirus, which was active, but the cause was never shown): that sharing
|
||||
/// violation is waited out (at most 5 s). On Linux a delete never meets one, so the first attempt is the only one.
|
||||
/// </summary>
|
||||
private static async Task DeleteClosedFileAsync(string path)
|
||||
{
|
||||
const int SharingViolation = unchecked((int)0x80070020);
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
return;
|
||||
}
|
||||
catch (IOException ex) when (OperatingSystem.IsWindows() && ex.HResult == SharingViolation && attempt < 100)
|
||||
{
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync() => Db.DisposeAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -163,10 +163,12 @@ public sealed class ImportApiTests
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, sources, "desktop: the native picker, no listing");
|
||||
}
|
||||
|
||||
// Docker: the sources live under /importa (absent on this machine: the listing says so).
|
||||
// Docker: the sources live under /importa (absent on this machine: the listing says so). The root is reported as
|
||||
// a full path: «/importa» in the container, rooted on the current drive where the edition runs for development
|
||||
// on Windows.
|
||||
await using var docker = await Part2.StartAsync();
|
||||
var overview = await docker.GetJsonAsync("/api/import");
|
||||
Assert.AreEqual("/importa", overview.Str("sourceRoot"));
|
||||
Assert.AreEqual(Path.GetFullPath("/importa"), overview.Str("sourceRoot"));
|
||||
Assert.IsFalse(overview.Bool("pickFolder"));
|
||||
var (pick, _) = await docker.SendJsonAsync(HttpMethod.Post, "/api/import/pick-folder");
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, pick);
|
||||
|
||||
Reference in new issue
Block a user