Skip to content

Commit 1da6fc1

Browse files
committed
Removed redundant cache clear
1 parent ad9b7f4 commit 1da6fc1

11 files changed

Lines changed: 114 additions & 58 deletions

File tree

src/Core/SecureFolderFS.Core.FileSystem/Chunks/CachingChunkAccess.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public override void Flush()
111111
if (item.Value.WasModified)
112112
chunkWriter.WriteChunk(item.Key, item.Value.Buffer.AsSpan(0, item.Value.ActualLength));
113113
}
114-
115-
_chunkCache.Clear();
116114
}
117115
}
118116

src/Core/SecureFolderFS.Core.FileSystem/Chunks/ChunkAccess.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public ChunkAccess(ChunkReader chunkReader, ChunkWriter chunkWriter, IContentCry
3535
/// <param name="chunkNumber">The number of chunk to copy from.</param>
3636
/// <param name="destination">The destination buffer to copy to.</param>
3737
/// <param name="offsetInChunk">The offset in chunk to start copying from.</param>
38-
/// <returns>The amount of bytes copied. If successful, value is non-negative.</returns>
38+
/// <returns>The number of bytes copied. If successful, value is non-negative.</returns>
3939
public virtual int CopyFromChunk(long chunkNumber, Span<byte> destination, int offsetInChunk)
4040
{
4141
// Rent buffer
@@ -74,7 +74,7 @@ public virtual int CopyFromChunk(long chunkNumber, Span<byte> destination, int o
7474
/// <param name="chunkNumber">The number of chunk to copy to.</param>
7575
/// <param name="source">The source buffer to copy from.</param>
7676
/// <param name="offsetInChunk">The offset in chunk to start copying to.</param>
77-
/// <returns>The amount of bytes copied. If successful, value is non-negative.</returns>
77+
/// <returns>The number of bytes copied. If successful, value is non-negative.</returns>
7878
public virtual int CopyToChunk(long chunkNumber, ReadOnlySpan<byte> source, int offsetInChunk)
7979
{
8080
// Rent buffer

src/Core/SecureFolderFS.Core.FileSystem/Chunks/ChunkReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ChunkReader(Security security, BufferHolder fileHeader, StreamsManager st
3333
/// </summary>
3434
/// <param name="chunkNumber">The chunk number to read at.</param>
3535
/// <param name="plaintextChunk">The plaintext chunk to write to.</param>
36-
/// <returns>The amount of plaintext bytes or -1 if integrity error occurred.</returns>
36+
/// <returns>The number of plaintext bytes or -1 if integrity error occurred.</returns>
3737
public int ReadChunk(long chunkNumber, Span<byte> plaintextChunk)
3838
{
3939
// Calculate sizes
@@ -67,7 +67,7 @@ public int ReadChunk(long chunkNumber, Span<byte> plaintextChunk)
6767
// Read from stream at correct chunk
6868
var read = ciphertextStream.Read(realCiphertextChunk);
6969

70-
// Check for end of file
70+
// Check for the end of the file
7171
if (read == FileSystem.Constants.FILE_EOF)
7272
return 0;
7373

src/Core/SecureFolderFS.Core.FileSystem/Streams/PlaintextStream.cs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public override void SetLength(long value)
170170
if (value == Length)
171171
return;
172172

173-
// Make sure header is ready before we can read/modify chunks
173+
// Make sure the header is ready before we can read/modify chunks
174174
if (!TryWriteHeader() && !_headerBuffer.ReadHeader(Inner, _security))
175175
throw new CryptographicException();
176176

@@ -191,7 +191,7 @@ public override void SetLength(long value)
191191
}
192192
else if (value > Length)
193193
{
194-
// Flush remaining chunks before base stream is accessed
194+
// Flush remaining chunks before the base stream is accessed
195195
_chunkAccess.Flush();
196196

197197
// Calculate plaintext size here because plaintext Length might not be initialized yet
@@ -259,6 +259,9 @@ public override void Close()
259259
/// <inheritdoc/>
260260
public override void Flush()
261261
{
262+
if (!CanWrite)
263+
throw FileSystemExceptions.StreamReadOnly;
264+
262265
// Only flush when there's a need to
263266
if (_chunkAccess.FlushAvailable)
264267
{
@@ -270,7 +273,7 @@ public override void Flush()
270273
private void WriteInternal(ReadOnlySpan<byte> buffer, long position)
271274
{
272275
if (!TryWriteHeader() && !_headerBuffer.ReadHeader(Inner, _security))
273-
throw new CryptographicException();
276+
throw new CryptographicException("Could not write nor read the header.");
274277

275278
var plaintextChunkSize = _security.ContentCrypt.ChunkPlaintextSize;
276279
var written = 0;
@@ -282,7 +285,6 @@ private void WriteInternal(ReadOnlySpan<byte> buffer, long position)
282285
var chunkNumber = currentPosition / plaintextChunkSize;
283286
var offsetInChunk = (int)(currentPosition % plaintextChunkSize);
284287
var length = Math.Min(buffer.Length - positionInBuffer, plaintextChunkSize - offsetInChunk);
285-
286288
var copy = _chunkAccess.CopyToChunk(
287289
chunkNumber,
288290
buffer.Slice(positionInBuffer),
@@ -309,43 +311,40 @@ private void WriteInternal(ReadOnlySpan<byte> buffer, long position)
309311
[SkipLocalsInit]
310312
private bool TryWriteHeader()
311313
{
312-
if (!CanWrite)
313-
throw FileSystemExceptions.StreamReadOnly;
314+
if (_headerBuffer.IsHeaderReady)
315+
return true;
314316

315317
lock (_writeLock)
316-
if (!_headerBuffer.IsHeaderReady && CanWrite)
318+
{
319+
// Check if there is data already written only when we can seek
320+
if (Inner.Length > 0L)
321+
return false;
322+
323+
// Make sure we save the header state
324+
_headerBuffer.IsHeaderReady = true;
325+
326+
// Allocate ciphertext header
327+
Span<byte> ciphertextHeader = stackalloc byte[_security.HeaderCrypt.HeaderCiphertextSize];
328+
329+
// Get and encrypt the header
330+
_security.HeaderCrypt.CreateHeader(_headerBuffer);
331+
_security.HeaderCrypt.EncryptHeader(_headerBuffer, ciphertextHeader);
332+
333+
// Write header
334+
if (CanSeek)
317335
{
318-
// Check if there is data already written only when we can seek
319-
if (Inner.Length > 0L)
320-
return false;
321-
322-
// Make sure we save the header state
323-
_headerBuffer.IsHeaderReady = true;
324-
325-
// Allocate ciphertext header
326-
Span<byte> ciphertextHeader = stackalloc byte[_security.HeaderCrypt.HeaderCiphertextSize];
327-
328-
// Get and encrypt the header
329-
_security.HeaderCrypt.CreateHeader(_headerBuffer);
330-
_security.HeaderCrypt.EncryptHeader(_headerBuffer, ciphertextHeader);
331-
332-
// Write header
333-
if (CanSeek)
334-
{
335-
var savedPosition = Inner.Position;
336-
Inner.Position = 0L;
337-
Inner.Write(ciphertextHeader);
338-
Inner.Position = savedPosition + ciphertextHeader.Length;
339-
}
340-
else
341-
{
342-
Inner.Write(ciphertextHeader);
343-
}
344-
345-
return true;
336+
var savedPosition = Inner.Position;
337+
Inner.Position = 0L;
338+
Inner.Write(ciphertextHeader);
339+
Inner.Position = savedPosition + ciphertextHeader.Length;
340+
}
341+
else
342+
{
343+
Inner.Write(ciphertextHeader);
346344
}
347345

348-
return false;
346+
return true;
347+
}
349348
}
350349

351350
private long AlignToChunkStartPosition(long plaintextPosition)

src/Platforms/Directory.Packages.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<PackageVersion Include="AathifMahir.Maui.MauiIcons.Material" Version="4.0.0" />
55
<PackageVersion Include="AcrylicView.Maui" Version="2.1.3" />
66
<PackageVersion Include="CommunityToolkit.Maui" Version="11.2.0" />
7-
<PackageVersion Include="CommunityToolkit.Maui.MediaElement" Version="6.0.2" />
87
<PackageVersion Include="CommunityToolkit.WinUI.Animations" Version="8.2.250402" />
98
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls.Markdown" Version="7.1.2" />
109
<PackageVersion Include="ContextMenuContainer" Version="1.2.3" />
@@ -21,7 +20,7 @@
2120
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
2221
<PackageVersion Include="Octokit" Version="14.0.0" />
2322
<PackageVersion Include="Plugin.Maui.BottomSheet" Version="9.1.4" />
24-
<PackageVersion Include="Sentry" Version="5.12.0" />
23+
<PackageVersion Include="Sentry" Version="5.16.0" />
2524
<PackageVersion Include="SkiaSharp" Version="3.119.0" />
2625
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="9.0.4" />
2726
<PackageVersion Include="Uno.CommunityToolkit.WinUI" Version="7.1.200" />

src/Platforms/SecureFolderFS.Maui/MauiProgram.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public static MauiApp CreateMauiApp()
2626
})
2727

2828
// Plugins
29-
.UseMauiCommunityToolkitMediaElement() // https://github.com/CommunityToolkit/Maui
3029
.UseMauiCommunityToolkit() // https://github.com/CommunityToolkit/Maui
3130
.UseBottomSheet() // https://github.com/lucacivale/Maui.BottomSheet
3231
.ConfigureContextMenuContainer() // https://github.com/anpin/ContextMenuContainer

src/Platforms/SecureFolderFS.Maui/Popups/CredentialsPopup.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
Clicked="ResetViewButton_Click"
3333
HorizontalOptions="Fill"
3434
IsEnabled="{Binding ViewModel.CanContinue, Mode=OneWay, Source={x:Reference ThisPopup}}"
35-
Style="{StaticResource AccentButtonStyle}"
35+
Style="{OnPlatform Android={StaticResource AccentButtonStyle},
36+
iOS={StaticResource NoBackgroundButtonStyle}}"
3637
Text="{Binding ViewModel.PrimaryText, Mode=OneWay, Source={x:Reference ThisPopup}}" />
3738
</VerticalStackLayout>
3839
</DataTemplate>

src/Platforms/SecureFolderFS.Maui/Views/Modals/Vault/FilePreviewModalPage.xaml.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using CommunityToolkit.Maui.Views;
21
using LibVLCSharp.MAUI;
32
using LibVLCSharp.Shared;
43
using SecureFolderFS.Maui.Extensions;
5-
using SecureFolderFS.Maui.Prompts;
64
using SecureFolderFS.Maui.TemplateSelectors;
75
using SecureFolderFS.Maui.UserControls;
86
using SecureFolderFS.Maui.UserControls.Common;
@@ -88,14 +86,6 @@ protected override async void OnDisappearing()
8886
(GalleryView.Next as IDisposable)?.Dispose();
8987
}
9088

91-
if ((Presentation.Content as ContentView)?.Content is MediaElement mediaElement)
92-
{
93-
mediaElement.Stop();
94-
mediaElement.Handler?.DisconnectHandler();
95-
mediaElement.Dispose();
96-
mediaElement.Source = null;
97-
}
98-
9989
if (ViewModel?.PreviewerViewModel is TextPreviewerViewModel { WasModified: true } textViewModel)
10090
{
10191
var overlayService = DI.Service<IOverlayService>();

src/Sdk/SecureFolderFS.Sdk.Ftp/SecureFolderFS.Sdk.Ftp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="FluentFTP" Version="53.0.1" />
9+
<PackageReference Include="FluentFTP" Version="53.0.2" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

src/Shared/SecureFolderFS.Shared/SecureFolderFS.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />
13-
<PackageReference Include="OwlCore.Storage" Version="0.12.3" />
13+
<PackageReference Include="OwlCore.Storage" Version="0.14.0" />
1414
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
1515
</ItemGroup>
1616

0 commit comments

Comments
 (0)