Skip to content

Commit

Permalink
expose local disk full path
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed May 31, 2024
1 parent ef45d24 commit 92612a6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: build

env:
v: '2.0.0'
v: '2.0.1'
av: '2.0.0'

on:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion docs/release-history.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
27 changes: 27 additions & 0 deletions src/Stowage.Test/Integration/Impl/LocalDiskTest.cs
Original file line number Diff line number Diff line change
@@ -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<IOEntry> entries = await _storage.Ls();
IOEntry entry = entries.First();

string nativePath = _storage.ToNativeLocalPath(entry.Path);

Assert.True(nativePath.Length > 0);
}
}
}
21 changes: 21 additions & 0 deletions src/Stowage/Impl/ILocalDiskFileStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stowage.Impl {

/// <summary>
/// Local disk specific functionality.
/// </summary>
public interface ILocalDiskFileStorage : IFileStorage {

/// <summary>
/// Converts <see cref="IOPath"/> obtained from local disk storage to native local path, which will be different on different platforms.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
string ToNativeLocalPath(IOPath path);
}
}
8 changes: 6 additions & 2 deletions src/Stowage/Impl/LocalDiskFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using SysIO = System.IO;

namespace Stowage.Impl {
class LocalDiskFileStorage : PolyfilledFileStorage {
class LocalDiskFileStorage : PolyfilledFileStorage, ILocalDiskFileStorage {
private readonly string _directoryFullName;

/// <summary>
Expand All @@ -33,7 +33,7 @@ private IReadOnlyCollection<IOEntry> List(IOPath? path, bool recurse, bool addAt
return fInfos.Select(i => ToIOEntry(i, addAttributes)).ToList();
}

return new IOEntry[0];
return Array.Empty<IOEntry>();
}

public override Task<IReadOnlyCollection<IOEntry>> Ls(IOPath? path = null, bool recurse = false, CancellationToken cancellationToken = default) {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 92612a6

Please sign in to comment.