diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 204deaf..390e581 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: build env: - v: '2.0.0' + v: '2.0.1' av: '2.0.0' on: @@ -29,7 +29,6 @@ jobs: with: dotnet-version: | 6.0.x - 7.0.x 8.0.x - name: Install dependencies run: dotnet restore src/Stowage.sln diff --git a/docs/release-history.md b/docs/release-history.md index b5fe855..22f73d3 100644 --- a/docs/release-history.md +++ b/docs/release-history.md @@ -1,4 +1,8 @@ -## 2.0.0 +## 2.0.1 + +Local disk file storage provider now implements `ILocalDiskFileStorage` interface, which exposes `ToNativeLocalPath` method returning full path to the file on the local disk, specific to the OS you are running on. This is useful when you need to pass file paths to external tools or libraries that need native OS paths. + +## 2.0.0 2.0.0 introduces massive *ergonomic improvements* and some breaking changes. diff --git a/src/Stowage.Test/Integration/Impl/LocalDiskTest.cs b/src/Stowage.Test/Integration/Impl/LocalDiskTest.cs new file mode 100644 index 0000000..fb014fd --- /dev/null +++ b/src/Stowage.Test/Integration/Impl/LocalDiskTest.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Stowage.Impl; +using Xunit; + +namespace Stowage.Test.Integration.Impl { + [Trait("Category", "Integration")] + public class LocalDiskTest { + private readonly ILocalDiskFileStorage _storage; + + public LocalDiskTest() { + _storage = (ILocalDiskFileStorage)Files.Of.LocalDisk(Environment.CurrentDirectory); + } + + [Fact] + public async Task ResolveToNativePath() { + IReadOnlyCollection entries = await _storage.Ls(); + IOEntry entry = entries.First(); + + string nativePath = _storage.ToNativeLocalPath(entry.Path); + + Assert.True(nativePath.Length > 0); + } + } +} diff --git a/src/Stowage/Impl/ILocalDiskFileStorage.cs b/src/Stowage/Impl/ILocalDiskFileStorage.cs new file mode 100644 index 0000000..13ba7ad --- /dev/null +++ b/src/Stowage/Impl/ILocalDiskFileStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stowage.Impl { + + /// + /// Local disk specific functionality. + /// + public interface ILocalDiskFileStorage : IFileStorage { + + /// + /// Converts obtained from local disk storage to native local path, which will be different on different platforms. + /// + /// + /// + string ToNativeLocalPath(IOPath path); + } +} diff --git a/src/Stowage/Impl/LocalDiskFileStorage.cs b/src/Stowage/Impl/LocalDiskFileStorage.cs index 017966d..e1dc0e8 100644 --- a/src/Stowage/Impl/LocalDiskFileStorage.cs +++ b/src/Stowage/Impl/LocalDiskFileStorage.cs @@ -8,7 +8,7 @@ using SysIO = System.IO; namespace Stowage.Impl { - class LocalDiskFileStorage : PolyfilledFileStorage { + class LocalDiskFileStorage : PolyfilledFileStorage, ILocalDiskFileStorage { private readonly string _directoryFullName; /// @@ -33,7 +33,7 @@ private IReadOnlyCollection List(IOPath? path, bool recurse, bool addAt return fInfos.Select(i => ToIOEntry(i, addAttributes)).ToList(); } - return new IOEntry[0]; + return Array.Empty(); } public override Task> Ls(IOPath? path = null, bool recurse = false, CancellationToken cancellationToken = default) { @@ -177,5 +177,9 @@ private Stream CreateStream(string fullPath, bool overwrite = true) { s.Seek(0, SeekOrigin.End); return s; } + + public string ToNativeLocalPath(IOPath path) { + return Path.Combine(_directoryFullName, path.NLS); + } } } \ No newline at end of file