Public Access
The remote pane's NAME column was blue for a directory and plain for everything else, and the PERMS column was faint whatever it said. Two colours now come off the mode, split across those two columns on purpose: NAME says what a row is, so a file with an execute bit is green there, and PERMS says what is notable about how it is set, so a file anyone may write to is amber over the characters that actually say so. Because the two never compete for one TextBlock, a world-writable executable shows both facts instead of one winning an argument. No new blue is spent, which is what App.axaml asks for: it reserves blue for a directory, a distinct scope, and calls it deliberately rare. Both are files only, and each exclusion is a wrong answer avoided rather than a case not got to. Every symbolic link is lrwxrwxrwx by convention and its mode governs nothing — what may be written is the target, whose mode an lstat listing never fetched — so amber there would fire on every link on the host. A world-writable directory is /tmp, made safe by a sticky bit PosixMode does not render, and warning about it would be warning about the half of the mode that is on screen while the half that answers the warning is not. And the execute bit on a directory means "may be searched", which is true of very nearly every directory a host has, so green there would paint the whole pane and mark nothing. The two questions read back the string PosixMode wrote rather than carrying its nine booleans through SftpEntry as well. That is the point rather than a shortcut: two representations of one fact is how a row ends up coloured for a bit the column beside it does not show. A mode of the wrong length answers false rather than throwing, since these decide a colour and a listing is not worth failing over one. The amber is Warn rather than WarnText, which is the muted amber a warning card writes its sentences in. At 9.5px against TextFaint that one is a shade rather than a signal, and a marker nobody notices is the same as no marker. The local pane is untouched, on the grounds it already gives for having no PERMS column at all: a POSIX mode is not a fact about a file on Windows, and colouring one there would invent exactly what the column declines to print. Twenty cases in RemotePathTests, which needs no container — the execute bit in any of the three triples rather than only the owner's, the others-write bit alone, a mode of the wrong length, and the file-only rule for both questions from all three kinds. dotnet format is clean and the app and layout suites pass at 109 and 35.
This commit is contained in:
@@ -83,6 +83,69 @@ public sealed class RemotePathTests
|
||||
.ShouldBe("lrwxrwxrwx");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-rwxr-xr-x", true)]
|
||||
[InlineData("-rw-r-xr--", true)]
|
||||
[InlineData("-rw-r--r-x", true)]
|
||||
[InlineData("-rw-r--r--", false)]
|
||||
[InlineData("----------", false)]
|
||||
public void PosixMode_ReadsAnExecuteBitInAnyTriple(string mode, bool expected)
|
||||
{
|
||||
// Any of the three, not the owner's: the account browsing is not necessarily the owner, and a file
|
||||
// that only the group may run is still a file somebody runs.
|
||||
PosixMode.HasAnyExecuteBit(mode).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-rw-rw-rw-", true)]
|
||||
[InlineData("-rw-rw-r--", false)]
|
||||
[InlineData("-rw-r--r--", false)]
|
||||
[InlineData("--------w-", true)]
|
||||
public void PosixMode_ReadsTheOthersWriteBit(string mode, bool expected)
|
||||
{
|
||||
// The others triple only. A group-writable file is writable by a named set of people, which is what
|
||||
// groups are for; this asks about the column that names nobody.
|
||||
PosixMode.IsWorldWritable(mode).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("rwxrwxrwx")]
|
||||
[InlineData("?")]
|
||||
public void PosixMode_AnswersFalseForAModeItDidNotWrite(string mode)
|
||||
{
|
||||
// These two decide a row's colour and nothing else. A listing is not worth failing over a string of
|
||||
// the wrong length, and an index off the end of one is how that would happen.
|
||||
PosixMode.HasAnyExecuteBit(mode).ShouldBeFalse();
|
||||
PosixMode.IsWorldWritable(mode).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SftpEntryKind.File, "-rwxr-xr-x", true)]
|
||||
[InlineData(SftpEntryKind.File, "-rw-r--r--", false)]
|
||||
[InlineData(SftpEntryKind.Directory, "drwxr-xr-x", false)]
|
||||
[InlineData(SftpEntryKind.SymbolicLink, "lrwxrwxrwx", false)]
|
||||
public void AnEntry_IsExecutableOnlyWhenItIsAFile(SftpEntryKind kind, string mode, bool expected)
|
||||
{
|
||||
// The x on a directory means "may be searched", which is true of very nearly every directory a host
|
||||
// has. A file browser that marked them all would be marking nothing.
|
||||
Entry(kind, mode).IsExecutable.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SftpEntryKind.File, "-rw-rw-rw-", true)]
|
||||
[InlineData(SftpEntryKind.File, "-rw-r--r--", false)]
|
||||
[InlineData(SftpEntryKind.SymbolicLink, "lrwxrwxrwx", false)]
|
||||
[InlineData(SftpEntryKind.Directory, "drwxrwxrwx", false)]
|
||||
public void AnEntry_IsWorldWritableOnlyWhenItIsAFile(SftpEntryKind kind, string mode, bool expected)
|
||||
{
|
||||
// The two exclusions are the point. Every symbolic link is lrwxrwxrwx and its mode governs nothing —
|
||||
// what may be written is the target, whose mode this listing never fetched. And a world-writable
|
||||
// directory is /tmp, made safe by a sticky bit PosixMode does not render: warning there would be
|
||||
// warning about the half of the mode that is on screen.
|
||||
Entry(kind, mode).IsWorldWritable.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, "0 B")]
|
||||
[InlineData(1023, "1023 B")]
|
||||
@@ -96,4 +159,8 @@ public sealed class RemotePathTests
|
||||
// "512.3 MB" claims a precision the figure does not have by the time it is that large.
|
||||
ByteSize.Format(bytes).ShouldBe(expected);
|
||||
}
|
||||
|
||||
/// <summary>An entry that is nothing but a kind and a mode, which is all these two questions read.</summary>
|
||||
private static SftpEntry Entry(SftpEntryKind kind, string mode) =>
|
||||
new("thing", "/tmp/thing", kind, 0, DateTimeOffset.UnixEpoch, mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user