Fix FTP regressions and broaden CI coverage
This commit is contained in:
4
.github/workflows/docker.yml
vendored
4
.github/workflows/docker.yml
vendored
@@ -2,10 +2,6 @@ name: Docker Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- codex/**
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
23
VirtualFS.Tests/Physical/SimpleFtpFileSystemTests.cs
Normal file
23
VirtualFS.Tests/Physical/SimpleFtpFileSystemTests.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.IO;
|
||||
using VirtualFS.Physical;
|
||||
|
||||
namespace VirtualFS.Tests.Physical;
|
||||
|
||||
public class SimpleFtpFileSystemTests
|
||||
{
|
||||
[Fact]
|
||||
public void DirectoryListingContainsEntryReturnsFalseWhenNameIsMissing()
|
||||
{
|
||||
using var reader = new StringReader("alpha\nbeta\ngamma\n");
|
||||
|
||||
Assert.False(SimpleFtpFileSystem.DirectoryListingContainsEntry(reader, "delta"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DirectoryListingContainsEntrySkipsDotEntries()
|
||||
{
|
||||
using var reader = new StringReader(".\n..\ntarget\n");
|
||||
|
||||
Assert.True(SimpleFtpFileSystem.DirectoryListingContainsEntry(reader, "target"));
|
||||
}
|
||||
}
|
||||
@@ -185,6 +185,39 @@ namespace VirtualFS.Physical
|
||||
LastAccessTime = item.Modified,
|
||||
});
|
||||
break;
|
||||
|
||||
case FtpObjectType.Link:
|
||||
if (item.LinkObject != null)
|
||||
{
|
||||
switch (item.LinkObject.Type)
|
||||
{
|
||||
case FtpObjectType.File:
|
||||
result.Add(new File()
|
||||
{
|
||||
IsReadOnly = IsReadOnly,
|
||||
Path = path + item.Name,
|
||||
FileSystem = this,
|
||||
CreationTime = item.LinkObject.Created,
|
||||
LastWriteTime = item.LinkObject.Modified,
|
||||
LastAccessTime = item.LinkObject.Modified,
|
||||
Size = item.LinkObject.Size,
|
||||
});
|
||||
break;
|
||||
|
||||
case FtpObjectType.Directory:
|
||||
result.Add(new Directory()
|
||||
{
|
||||
IsReadOnly = IsReadOnly,
|
||||
Path = string.Concat(path, item.Name.TrimEnd('/'), "/"),
|
||||
FileSystem = this,
|
||||
CreationTime = item.LinkObject.Created,
|
||||
LastWriteTime = item.LinkObject.Modified,
|
||||
LastAccessTime = item.LinkObject.Modified,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +259,10 @@ namespace VirtualFS.Physical
|
||||
base.DirectoryDelete(path, recursive);
|
||||
|
||||
using (FtpClient conn = GetConnection())
|
||||
conn.DeleteDirectory(GetFtpPath(path));
|
||||
if (recursive)
|
||||
conn.DeleteDirectory(GetFtpPath(path), FtpListOption.Recursive);
|
||||
else
|
||||
conn.DeleteDirectory(GetFtpPath(path));
|
||||
}
|
||||
|
||||
/// <summary>Opens an existing file for reading.</summary>
|
||||
|
||||
@@ -86,24 +86,7 @@ namespace VirtualFS.Physical
|
||||
FtpDoStuff(WebRequestMethods.Ftp.ListDirectory, path, null, r =>
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(r.GetResponseStream()))
|
||||
{
|
||||
string str = sr.ReadLine();
|
||||
while (str != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str) || str == "." || str == "..")
|
||||
{
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str == path.Name)
|
||||
{
|
||||
res = true;
|
||||
sr.ReadToEnd();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
res = DirectoryListingContainsEntry(sr, path.Name);
|
||||
});
|
||||
|
||||
return res;
|
||||
@@ -245,6 +228,17 @@ namespace VirtualFS.Physical
|
||||
{
|
||||
base.DirectoryDelete(path, recursive);
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
foreach (var entry in GetEntries(path))
|
||||
{
|
||||
if (entry.IsDirectory)
|
||||
DirectoryDelete(entry.Path, recursive: true);
|
||||
else
|
||||
FileDelete(entry.Path);
|
||||
}
|
||||
}
|
||||
|
||||
FtpDoStuff(WebRequestMethods.Ftp.RemoveDirectory, path);
|
||||
}
|
||||
|
||||
@@ -373,6 +367,21 @@ namespace VirtualFS.Physical
|
||||
return resp.StatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool DirectoryListingContainsEntry(TextReader reader, string name)
|
||||
{
|
||||
string line = reader.ReadLine();
|
||||
|
||||
while (line != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(line) && line != "." && line != ".." && line == name)
|
||||
return true;
|
||||
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#pragma warning restore SYSLIB0014
|
||||
}
|
||||
|
||||
@@ -27,4 +27,10 @@
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>VirtualFS.Tests</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user