Skip to content

Commit 7a62977

Browse files
.Net Standard 2.0 support (#2)
1 parent af4ed9d commit 7a62977

18 files changed

+203
-151
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
99

1010
### Changed
1111
- Initial version after fork.
12+
- .Net Standard 2.0 support.
13+
- System.IO.Abstractions 21.0.29 support.
14+
- SMBLibrary 1.5.3.5 support.
1215

1316
## [1.1.15] 2020-06-19
1417

Directory.Build.props

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<Project>
22
<PropertyGroup>
3-
<Product>System.IO.Abstractions</Product>
3+
<Product>InkSoft.SmbAbstraction</Product>
44
<Copyright>Copyright © Inktavo 2024</Copyright>
55
<Authors>Inktavo</Authors>
6+
<Company>Inktavo</Company>
67
<SignAssembly Condition="'$(Configuration)' == 'Release'">True</SignAssembly>
78
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
89
<LangVersion>12</LangVersion>
9-
<PackageTags>testing</PackageTags>
10+
<PackageTags>IFileSystem;SMB;UNC;System.IO.Abstractions;SMBLibrary;SMBAbstraction;Linux</PackageTags>
1011
<PackageProjectUrl>https://github.com/Printavo/SmbAbstraction</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/Printavo/SmbAbstraction</RepositoryUrl>
1113
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1214
<PackageReadmeFile>README.md</PackageReadmeFile>
1315
<DefineConstants Condition="'$(TargetFramework)' != 'net462'">$(DefineConstants);FEATURE_FILE_SYSTEM_ACL_EXTENSIONS</DefineConstants>
@@ -27,6 +29,10 @@
2729
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2830
<PrivateAssets>all</PrivateAssets>
2931
</PackageReference>
32+
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="Nullable" Version="1.3.1">
33+
<PrivateAssets>all</PrivateAssets>
34+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
35+
</PackageReference>
3036
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath=""/>
3137
</ItemGroup>
32-
</Project>
38+
</Project>

InkSoft.SmbAbstraction.IntegrationTests/SmbAbstraction.IntegrationTests.csproj renamed to InkSoft.SmbAbstraction.IntegrationTests/InkSoft.SmbAbstraction.IntegrationTests.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
<TargetFramework>net8.0</TargetFramework>
44
<IsPackable>false</IsPackable>
55
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
6+
<IsTestProject>true</IsTestProject>
7+
<Configurations>Debug</Configurations>
68
</PropertyGroup>
79
<ItemGroup>
8-
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.1.0" />
10+
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
911
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
1012
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
1113
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
1214
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
14-
<PackageReference Include="xunit" Version="2.4.0" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
16-
<PackageReference Include="coverlet.collector" Version="1.0.1" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
16+
<PackageReference Include="xunit" Version="2.9.0" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
<PackageReference Include="coverlet.collector" Version="6.0.2">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageReference>
1725
<ProjectReference Include="..\InkSoft.SmbAbstraction\InkSoft.SmbAbstraction.csproj" />
1826
</ItemGroup>
1927
<ItemGroup>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<IsPackable>false</IsPackable>
5+
<IsTestProject>true</IsTestProject>
6+
<Configurations>Debug</Configurations>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
10+
<PackageReference Include="xunit" Version="2.9.0" />
11+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="coverlet.collector" Version="6.0.2">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
<PackageReference Include="FakeItEasy" Version="8.3.0" />
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ProjectReference Include="..\InkSoft.SmbAbstraction\InkSoft.SmbAbstraction.csproj" />
23+
</ItemGroup>
24+
</Project>

InkSoft.SmbAbstraction.Tests/SmbAbstraction.Tests.csproj

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net8.0</TargetFrameworks>
4-
<PackOnBuild>true</PackOnBuild>
3+
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
54
<NeutralLanguage>en-US</NeutralLanguage>
6-
<Description>This library implements the System.IO.Abstractions interfaces for interacting with the filesystem, and adds support for interacting with UNC or SMB paths.</Description>
5+
<Description>This project is a fork of https://github.com/jordanlytle/SmbAbstraction with a few key differences: 1) It uses the original SMBLibrary as opposed to SMBLibraryLite, 2) It conforms to newer versions of https://github.com/TestableIO/System.IO.Abstractions interfaces, and 3) it also targets .Net Standard 2.0. This library implements the System.IO.Abstractions interfaces for interacting with the filesystem and adds support for interacting with UNC or SMB paths from non-Windows and Windos clients outside an Active Directory domain.</Description>
76
<PackageId>InkSoft.SmbAbstraction</PackageId>
8-
<RepositoryUrl>https://github.com/Printavo/SmbAbstraction</RepositoryUrl>
97
<RepositoryType>git</RepositoryType>
8+
<Version>0.1.0</Version>
109
<PackageVersion>0.1.0</PackageVersion>
1110
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1211
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1312
<IncludeSymbols>true</IncludeSymbols>
13+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
14+
<PackageIcon>PackageIcon.png</PackageIcon>
1415
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
15-
<Version>0.1.0</Version>
16+
<Title>SMBLibrary to IFileSystem compatibility shim</Title>
17+
<PackageReleaseNotes>Initial fork from original SmbAbstraction project.</PackageReleaseNotes>
18+
<SignAssembly>True</SignAssembly>
1619
</PropertyGroup>
1720
<ItemGroup>
1821
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
1922
<PackageReference Include="SMBLibrary" Version="1.5.3.5" />
2023
<PackageReference Include="System.IO.Abstractions" Version="21.0.29" />
21-
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2">
22-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23-
<PrivateAssets>all</PrivateAssets>
24-
</PackageReference>
24+
<None Include="PackageIcon.png" Pack="true" PackagePath="" />
2525
</ItemGroup>
2626
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if NETSTANDARD2_0
2+
using System;
3+
using System.Text.RegularExpressions;
4+
5+
namespace InkSoft.SmbAbstraction;
6+
7+
/// <summary>
8+
/// TODO: Is there a canned nuget package that fills compatibility gaps for basic string operations in older .NET versions?
9+
/// </summary>
10+
public static class NetStandard20Extensions
11+
{
12+
public static bool Contains(this string s, char value) => s.Contains(value.ToString());
13+
14+
public static bool EndsWith(this string s, char value) => s.Length > 0 && s[s.Length - 1] == value;
15+
16+
public static string Replace(this string s, string oldValue, string? newValue, StringComparison comparisonType) => comparisonType switch
17+
{
18+
StringComparison.OrdinalIgnoreCase
19+
or StringComparison.InvariantCultureIgnoreCase
20+
or StringComparison.CurrentCultureIgnoreCase
21+
=> Regex.Replace(s, oldValue, newValue, RegexOptions.IgnoreCase),
22+
_
23+
=> s.Replace(oldValue, newValue),
24+
};
25+
}
26+
#endif
27.5 KB
Loading

InkSoft.SmbAbstraction/PathExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static bool TryResolveHostname(this string hostnameOrAddress, out IPAddre
105105
public static string ShareName(this string path)
106106
{
107107
var uri = new Uri(path);
108-
string? shareName = uri.Segments[1].RemoveAnySeperators();
108+
string? shareName = uri.Segments[1].RemoveAnySeparators();
109109

110110
return shareName;
111111
}
@@ -116,9 +116,9 @@ public static string SharePath(this string path)
116116

117117
string sharePath = "";
118118
if (uri.Scheme.Equals("smb"))
119-
sharePath = $"{uri.Scheme}://{uri.Host}/{uri.Segments[1].RemoveAnySeperators()}";
119+
sharePath = $"{uri.Scheme}://{uri.Host}/{uri.Segments[1].RemoveAnySeparators()}";
120120
else if (uri.IsUnc)
121-
sharePath = $@"\\{uri.Host}\{uri.Segments[1].RemoveAnySeperators()}";
121+
sharePath = $@"\\{uri.Host}\{uri.Segments[1].RemoveAnySeparators()}";
122122

123123
return sharePath;
124124
}
@@ -135,7 +135,7 @@ public static string GetParentPath(this string path)
135135
var pathUri = new Uri(path);
136136
var parentUri = pathUri.AbsoluteUri.EndsWith('/') ? new(pathUri, "..") : new Uri(pathUri, ".");
137137
string? pathString = parentUri.IsUnc ? parentUri.LocalPath : Uri.UnescapeDataString(parentUri.AbsoluteUri);
138-
return pathString.RemoveTrailingSeperators();
138+
return pathString.RemoveTrailingSeparators();
139139
}
140140

141141
public static string GetLastPathSegment(this string path)
@@ -144,7 +144,7 @@ public static string GetLastPathSegment(this string path)
144144
return Uri.UnescapeDataString(uri.Segments.Last());
145145
}
146146

147-
public static string RemoveLeadingAndTrailingSeparators(this string input) => input.RemoveLeadingSeparators().RemoveTrailingSeperators();
147+
public static string RemoveLeadingAndTrailingSeparators(this string input) => input.RemoveLeadingSeparators().RemoveTrailingSeparators();
148148

149149
public static string RemoveLeadingSeparators(this string input)
150150
{
@@ -159,7 +159,7 @@ public static string RemoveLeadingSeparators(this string input)
159159
return input;
160160
}
161161

162-
public static string RemoveTrailingSeperators(this string input)
162+
public static string RemoveTrailingSeparators(this string input)
163163
{
164164
foreach (string? pathSeperator in s_pathSeparators)
165165
{
@@ -172,7 +172,7 @@ public static string RemoveTrailingSeperators(this string input)
172172
return input;
173173
}
174174

175-
private static string RemoveAnySeperators(this string input)
175+
private static string RemoveAnySeparators(this string input)
176176
{
177177
foreach (string? pathSeparator in s_pathSeparators)
178178
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#if FEATURE_ASYNC_FILE
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Threading;
8+
9+
namespace InkSoft.SmbAbstraction
10+
{
11+
partial class SmbFile
12+
{
13+
/// <inheritdoc />
14+
public override Task AppendAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => AppendAllLines(path, contents), cancellationToken) : base.AppendAllLinesAsync(path, contents, cancellationToken);
15+
16+
/// <inheritdoc />
17+
public override Task AppendAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => AppendAllLines(path, contents, encoding), cancellationToken) : base.AppendAllLinesAsync(path, contents, encoding, cancellationToken);
18+
19+
/// <inheritdoc />
20+
public override Task AppendAllTextAsync(string path, string contents, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => AppendAllText(path, contents), cancellationToken) : base.AppendAllTextAsync(path, contents, cancellationToken);
21+
22+
/// <inheritdoc />
23+
public override Task AppendAllTextAsync(string path, string contents, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => AppendAllText(path, contents, encoding), cancellationToken) : base.AppendAllTextAsync(path, contents, encoding, cancellationToken);
24+
25+
/// <inheritdoc />
26+
public override Task<byte[]> ReadAllBytesAsync(string path, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => ReadAllBytes(path), cancellationToken) : base.ReadAllBytesAsync(path, cancellationToken);
27+
28+
/// <inheritdoc />
29+
public override Task<string[]> ReadAllLinesAsync(string path, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => ReadAllLines(path), cancellationToken) : base.ReadAllLinesAsync(path, cancellationToken);
30+
31+
/// <inheritdoc />
32+
public override Task<string[]> ReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => ReadAllLines(path, encoding), cancellationToken) : base.ReadAllLinesAsync(path, encoding, cancellationToken);
33+
34+
/// <inheritdoc />
35+
public override Task<string> ReadAllTextAsync(string path, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => ReadAllText(path), cancellationToken) : base.ReadAllTextAsync(path, cancellationToken);
36+
37+
/// <inheritdoc />
38+
public override Task<string> ReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => ReadAllText(path, encoding), cancellationToken) : base.ReadAllTextAsync(path, encoding, cancellationToken);
39+
40+
#if FEATURE_READ_LINES_ASYNC
41+
/// <inheritdoc />
42+
public override IAsyncEnumerable<string> ReadLinesAsync(string path, CancellationToken cancellationToken = default) => path.IsSharePath() ? throw new NotImplementedException() : base.ReadLinesAsync(path, cancellationToken);
43+
44+
/// <inheritdoc />
45+
public override IAsyncEnumerable<string> ReadLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? throw new NotImplementedException() : base.ReadLinesAsync(path, encoding, cancellationToken);
46+
#endif
47+
48+
/// <inheritdoc />
49+
public override Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => WriteAllBytes(path, bytes), cancellationToken) : base.WriteAllBytesAsync(path, bytes, cancellationToken);
50+
51+
/// <inheritdoc />
52+
public override Task WriteAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => WriteAllLines(path, contents), cancellationToken) : base.WriteAllLinesAsync(path, contents, cancellationToken);
53+
54+
/// <inheritdoc />
55+
public override Task WriteAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => WriteAllLines(path, contents, encoding), cancellationToken) : base.WriteAllLinesAsync(path, contents, encoding, cancellationToken);
56+
57+
/// <inheritdoc />
58+
public override Task WriteAllTextAsync(string path, string contents, CancellationToken cancellationToken = default) => path.IsSharePath() ? new(() => WriteAllText(path, contents), cancellationToken) : base.WriteAllTextAsync(path, contents, cancellationToken);
59+
60+
/// <inheritdoc />
61+
public override Task WriteAllTextAsync(string path, string contents, Encoding encoding, CancellationToken cancellationToken = default) => !path.IsSharePath() ? base.WriteAllTextAsync(path, contents, encoding, cancellationToken) : new(() => WriteAllText(path, contents, encoding), cancellationToken);
62+
}
63+
}
64+
#endif

0 commit comments

Comments
 (0)