Skip to content

Commit

Permalink
fix(storage): Fix issues raised by unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Oct 10, 2020
1 parent 323c292 commit 0d0d85e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Uno.UWP/Storage/StorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ public IAsyncOperation<BasicProperties> GetBasicPropertiesAsync()
=> AsyncOperation.FromTask(_impl.GetBasicProperties);

public IAsyncOperation<IRandomAccessStreamWithContentType> OpenReadAsync()
=> AsyncOperation<IRandomAccessStreamWithContentType>.FromTask((ct, _) => _impl.Open(ct, FileAccessMode.Read, StorageOpenOptions.None));
=> AsyncOperation<IRandomAccessStreamWithContentType>.FromTask((ct, _) => _impl.Open(ct, FileAccessMode.Read, StorageOpenOptions.AllowReadersAndWriters));

public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode)
=> AsyncOperation<IRandomAccessStream>.FromTask(async (ct, _) => await _impl.Open(ct, accessMode, StorageOpenOptions.None));
=> AsyncOperation<IRandomAccessStream>.FromTask(async (ct, _) => await _impl.Open(ct, accessMode, StorageOpenOptions.AllowReadersAndWriters));

public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)
=> AsyncOperation<IRandomAccessStream>.FromTask(async (ct, _) => await _impl.Open(ct, accessMode, options));

public IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync()
=> AsyncOperation<StorageStreamTransaction>.FromTask((ct, _) => _impl.OpenTransactedWrite(ct, StorageOpenOptions.None));
=> AsyncOperation<StorageStreamTransaction>.FromTask((ct, _) => _impl.OpenTransactedWrite(ct, StorageOpenOptions.AllowReadersAndWriters));

[NotImplemented] // The options is ignored, we implement this only to increase compatibility
public IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(StorageOpenOptions options)
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Storage/Streams/FileInputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed partial class FileInputStream : IInputStream, IDisposable, IStream

internal FileInputStream(string path, FileShare fileShare, ulong position)
{
_stream = File.Open(path, FileMode.Open, FileAccess.Read, fileShare);
_stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Read, fileShare);
_stream.Seek((long)position, SeekOrigin.Begin);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Storage/Streams/FileOutputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed partial class FileOutputStream : IOutputStream, IDisposable, IStre

internal FileOutputStream(string path, FileShare fileShare, ulong position)
{
_stream = File.Open(path, FileMode.Open, FileAccess.Write, fileShare);
_stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, fileShare);
_stream.Seek((long)position, SeekOrigin.Begin);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Uno.UWP/Storage/Streams/FileRandomAccessStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal FileRandomAccessStream(string path, FileAccess access, FileShare share)
share |= readWriteAccess;

_share = share;
_source = File.Open(_path, FileMode.Open, access, share);
_source = File.Open(_path, FileMode.OpenOrCreate, access, share);
}

Stream IStreamWrapper.FindStream() => _source;
Expand All @@ -47,7 +47,7 @@ public IInputStream GetInputStreamAt(ulong position)
{
if (!CanRead)
{
throw new InvalidOperationException("The file has been opened for read.");
throw new NotSupportedException("The file has been opened for read.");
}

return new FileInputStream(_path, _share, position);
Expand All @@ -57,7 +57,7 @@ public IOutputStream GetOutputStreamAt(ulong position)
{
if (!CanWrite)
{
throw new InvalidOperationException("The file has been opened for write.");
throw new NotSupportedException("The file has been opened for write.");
}

return new FileOutputStream(_path, _share, position);
Expand Down

0 comments on commit 0d0d85e

Please sign in to comment.