Replace legacy FTP dependency and add CI
This commit is contained in:
20
.github/workflows/docker.yml
vendored
Normal file
20
.github/workflows/docker.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Docker Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- codex/**
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
docker-test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build test image
|
||||
run: docker build --target test -t virtualfs:test .
|
||||
@@ -8,6 +8,7 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
|
||||
<NoWarn>$(NoWarn);MTP0001</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -46,6 +46,16 @@ namespace VirtualFS.EmbeddedResource
|
||||
/// <summary>Gets the assembly on which file system operates.</summary>
|
||||
public Assembly Assembly { get; private set; }
|
||||
|
||||
private string AssemblyLocation
|
||||
{
|
||||
get { return string.IsNullOrEmpty(Assembly.Location) ? null : Assembly.Location; }
|
||||
}
|
||||
|
||||
private DateTime AssemblyTimestamp(Func<System.IO.FileInfo, DateTime> selector)
|
||||
{
|
||||
return string.IsNullOrEmpty(AssemblyLocation) ? DateTime.UtcNow : selector(new System.IO.FileInfo(AssemblyLocation));
|
||||
}
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="EmbeddedResourceFileSystem"/> class.</summary>
|
||||
/// <param name="assembly">The assembly.</param>
|
||||
/// <param name="rootNamespace">The root namespace.</param>
|
||||
@@ -55,8 +65,6 @@ namespace VirtualFS.EmbeddedResource
|
||||
{
|
||||
Assembly = assembly;
|
||||
|
||||
var fi = new System.IO.FileInfo(Uri.UnescapeDataString(new UriBuilder(Assembly.CodeBase).Path));
|
||||
|
||||
_pathToResource = Assembly.GetManifestResourceNames()
|
||||
.Where(x => (string.IsNullOrEmpty(rootNamespace) || x.StartsWith(rootNamespace)) && (filter == null || filter.IsMatch(x)))
|
||||
.Select(x => new File()
|
||||
@@ -65,9 +73,9 @@ namespace VirtualFS.EmbeddedResource
|
||||
IsReadOnly = IsReadOnly,
|
||||
Path = ResourceToPath(rootNamespace, x),
|
||||
FileSystem = this,
|
||||
CreationTime = fi.CreationTimeUtc,
|
||||
LastAccessTime = fi.LastAccessTime,
|
||||
LastWriteTime = fi.LastWriteTime,
|
||||
CreationTime = AssemblyTimestamp(fi => fi.CreationTimeUtc),
|
||||
LastAccessTime = AssemblyTimestamp(fi => fi.LastAccessTimeUtc),
|
||||
LastWriteTime = AssemblyTimestamp(fi => fi.LastWriteTimeUtc),
|
||||
Size = 0,
|
||||
})
|
||||
.ToDictionary(
|
||||
@@ -86,9 +94,9 @@ namespace VirtualFS.EmbeddedResource
|
||||
IsReadOnly = IsReadOnly,
|
||||
Path = p,
|
||||
FileSystem = this,
|
||||
CreationTime = fi.CreationTimeUtc,
|
||||
LastAccessTime = fi.LastAccessTime,
|
||||
LastWriteTime = fi.LastWriteTime,
|
||||
CreationTime = AssemblyTimestamp(fi => fi.CreationTimeUtc),
|
||||
LastAccessTime = AssemblyTimestamp(fi => fi.LastAccessTimeUtc),
|
||||
LastWriteTime = AssemblyTimestamp(fi => fi.LastWriteTimeUtc),
|
||||
}));
|
||||
|
||||
// Ugly but it works (fix this - performance)
|
||||
@@ -143,17 +151,15 @@ namespace VirtualFS.EmbeddedResource
|
||||
|
||||
if (!ret && path.IsDirectory && _pathToResource.Keys.Any(x => x.IsParentOf(path)))
|
||||
{
|
||||
var fi = new System.IO.FileInfo(Uri.UnescapeDataString(new UriBuilder(Assembly.CodeBase).Path));
|
||||
|
||||
_pathToResource.Add(path, new Directory()
|
||||
{
|
||||
Data = null,
|
||||
IsReadOnly = IsReadOnly,
|
||||
Path = path,
|
||||
FileSystem = this,
|
||||
CreationTime = fi.CreationTimeUtc,
|
||||
LastAccessTime = fi.LastAccessTime,
|
||||
LastWriteTime = fi.LastWriteTime,
|
||||
CreationTime = AssemblyTimestamp(fi => fi.CreationTimeUtc),
|
||||
LastAccessTime = AssemblyTimestamp(fi => fi.LastAccessTimeUtc),
|
||||
LastWriteTime = AssemblyTimestamp(fi => fi.LastWriteTimeUtc),
|
||||
});
|
||||
|
||||
ret = true;
|
||||
@@ -182,7 +188,7 @@ namespace VirtualFS.EmbeddedResource
|
||||
/// should return null if real path can't be determined.</remarks>
|
||||
public override string EntryRealPath(Path path)
|
||||
{
|
||||
return Uri.UnescapeDataString(new UriBuilder(Assembly.CodeBase).Path);
|
||||
return AssemblyLocation;
|
||||
}
|
||||
|
||||
/// <summary>Get entries located under given path.</summary>
|
||||
@@ -213,4 +219,4 @@ namespace VirtualFS.EmbeddedResource
|
||||
return new VirtualStream(this, Assembly.GetManifestResourceStream(_pathToResource[path].Data.ToString()), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.FtpClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentFTP;
|
||||
using VirtualFS.Base;
|
||||
using VirtualFS.Implementation;
|
||||
|
||||
@@ -157,11 +157,11 @@ namespace VirtualFS.Physical
|
||||
{
|
||||
foreach (FtpListItem item in conn
|
||||
.GetListing(GetFtpPath(path),
|
||||
FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks | FtpListOption.AllFiles))
|
||||
FtpListOption.Modify | FtpListOption.Size | FtpListOption.AllFiles))
|
||||
{
|
||||
switch (item.Type)
|
||||
{
|
||||
case FtpFileSystemObjectType.File:
|
||||
case FtpObjectType.File:
|
||||
result.Add(new File()
|
||||
{
|
||||
IsReadOnly = IsReadOnly,
|
||||
@@ -174,7 +174,7 @@ namespace VirtualFS.Physical
|
||||
});
|
||||
break;
|
||||
|
||||
case FtpFileSystemObjectType.Directory:
|
||||
case FtpObjectType.Directory:
|
||||
result.Add(new Directory()
|
||||
{
|
||||
IsReadOnly = IsReadOnly,
|
||||
@@ -185,41 +185,6 @@ namespace VirtualFS.Physical
|
||||
LastAccessTime = item.Modified,
|
||||
});
|
||||
break;
|
||||
|
||||
case FtpFileSystemObjectType.Link:
|
||||
|
||||
if (item.LinkObject != null)
|
||||
{
|
||||
switch (item.LinkObject.Type)
|
||||
{
|
||||
case FtpFileSystemObjectType.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 FtpFileSystemObjectType.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,13 +331,13 @@ namespace VirtualFS.Physical
|
||||
private FtpClient GetConnection()
|
||||
{
|
||||
FtpClient conn = new FtpClient();
|
||||
conn.DataConnectionType = ConnectionType;
|
||||
conn.Host = _ftpServer;
|
||||
conn.Port = _ftpServerPort;
|
||||
|
||||
conn.Credentials = new NetworkCredential(_userName, _password);
|
||||
conn.Config.DataConnectionType = ConnectionType;
|
||||
conn.Connect();
|
||||
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ using VirtualFS.Implementation;
|
||||
|
||||
namespace VirtualFS.Physical
|
||||
{
|
||||
#pragma warning disable SYSLIB0014
|
||||
/// <summary>Ftp file system implementation.</summary>
|
||||
/// <remarks>This is very, very simple implementation
|
||||
/// of a FTP file system. Use this when regular FTP won't do the job.</remarks>
|
||||
@@ -373,4 +374,5 @@ namespace VirtualFS.Physical
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore SYSLIB0014
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="FluentFTP" Version="53.0.2" />
|
||||
<PackageReference Include="SharpZipLib" Version="1.4.2" />
|
||||
<PackageReference Include="SSH.NET" Version="2024.0.0" />
|
||||
<PackageReference Include="System.Net.FtpClient" Version="1.0.5824.34026" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">
|
||||
|
||||
Reference in New Issue
Block a user