Skip to content

Commit 92612a6

Browse files
committed
expose local disk full path
1 parent ef45d24 commit 92612a6

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: build
22

33
env:
4-
v: '2.0.0'
4+
v: '2.0.1'
55
av: '2.0.0'
66

77
on:
@@ -29,7 +29,6 @@ jobs:
2929
with:
3030
dotnet-version: |
3131
6.0.x
32-
7.0.x
3332
8.0.x
3433
- name: Install dependencies
3534
run: dotnet restore src/Stowage.sln

docs/release-history.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## 2.0.0
1+
## 2.0.1
2+
3+
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.
4+
5+
## 2.0.0
26

37
2.0.0 introduces massive *ergonomic improvements* and some breaking changes.
48

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Stowage.Impl;
6+
using Xunit;
7+
8+
namespace Stowage.Test.Integration.Impl {
9+
[Trait("Category", "Integration")]
10+
public class LocalDiskTest {
11+
private readonly ILocalDiskFileStorage _storage;
12+
13+
public LocalDiskTest() {
14+
_storage = (ILocalDiskFileStorage)Files.Of.LocalDisk(Environment.CurrentDirectory);
15+
}
16+
17+
[Fact]
18+
public async Task ResolveToNativePath() {
19+
IReadOnlyCollection<IOEntry> entries = await _storage.Ls();
20+
IOEntry entry = entries.First();
21+
22+
string nativePath = _storage.ToNativeLocalPath(entry.Path);
23+
24+
Assert.True(nativePath.Length > 0);
25+
}
26+
}
27+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Stowage.Impl {
8+
9+
/// <summary>
10+
/// Local disk specific functionality.
11+
/// </summary>
12+
public interface ILocalDiskFileStorage : IFileStorage {
13+
14+
/// <summary>
15+
/// Converts <see cref="IOPath"/> obtained from local disk storage to native local path, which will be different on different platforms.
16+
/// </summary>
17+
/// <param name="path"></param>
18+
/// <returns></returns>
19+
string ToNativeLocalPath(IOPath path);
20+
}
21+
}

src/Stowage/Impl/LocalDiskFileStorage.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using SysIO = System.IO;
99

1010
namespace Stowage.Impl {
11-
class LocalDiskFileStorage : PolyfilledFileStorage {
11+
class LocalDiskFileStorage : PolyfilledFileStorage, ILocalDiskFileStorage {
1212
private readonly string _directoryFullName;
1313

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

36-
return new IOEntry[0];
36+
return Array.Empty<IOEntry>();
3737
}
3838

3939
public override Task<IReadOnlyCollection<IOEntry>> Ls(IOPath? path = null, bool recurse = false, CancellationToken cancellationToken = default) {
@@ -177,5 +177,9 @@ private Stream CreateStream(string fullPath, bool overwrite = true) {
177177
s.Seek(0, SeekOrigin.End);
178178
return s;
179179
}
180+
181+
public string ToNativeLocalPath(IOPath path) {
182+
return Path.Combine(_directoryFullName, path.NLS);
183+
}
180184
}
181185
}

0 commit comments

Comments
 (0)