Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Implemented file name shortening#129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c791a5
Begin work on shortening
d2dyno1 a25e59d
Added name shortening vault option
d2dyno1 dc85c4c
Implement shortening for CryptoFolder
d2dyno1 97c339a
Apply partial code review
d2dyno1 240e023
Fix Recycle Bin restore with sidecar names
d2dyno1 071f0c6
Fixed threshold detection in RestoreRoutine
d2dyno1 94e810f
Detect orphan sidecar files in vault health
d2dyno1 f8a398e
Apply code review
d2dyno1 c28b045
Implemented sidecar logic for Dokany and WinFsp
d2dyno1 23a13d6
Added shortening and recycle bin support to FUSE
d2dyno1 320818f
Added name shortening to MAUI
d2dyno1 2d5b5b4
Update MockVaultHelpers.V4.cs
d2dyno1 4cf01a3
fix: detect shortened directories during restore finalization
Copilot e9be5a1
Apply code review
d2dyno1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7 src/Core/SecureFolderFS.Core.Dokany/AppModels/DokanyOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 28 additions & 1 deletion
29 src/Core/SecureFolderFS.Core.Dokany/Callbacks/OnDeviceDokany.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 83 additions & 21 deletions
104 src/Core/SecureFolderFS.Core.FUSE/Callbacks/OnDeviceFuse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using OwlCore.Storage; | ||
| using SecureFolderFS.Core.FileSystem; | ||
| using SecureFolderFS.Core.FileSystem.Helpers; | ||
| using SecureFolderFS.Core.FileSystem.Helpers.Paths; | ||
| using SecureFolderFS.Core.FileSystem.Helpers.Paths.Abstract; | ||
| using SecureFolderFS.Core.FileSystem.Helpers.Paths.Native; | ||
| using SecureFolderFS.Core.FileSystem.Helpers.RecycleBin.Native; | ||
| using SecureFolderFS.Core.FUSE.OpenHandles; | ||
| using SecureFolderFS.Core.FUSE.UnsafeNative; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using SecureFolderFS.Core.FileSystem.Helpers.Paths.Abstract; | ||
| using Tmds.Fuse; | ||
| using Tmds.Linux; | ||
| using static SecureFolderFS.Core.FUSE.UnsafeNative.UnsafeNativeApis; | ||
| @@ -65,7 +68,7 @@ public override unsafe int Create(ReadOnlySpan<byte> path, mode_t mode, ref Fuse | ||
| if (FuseOptions!.IsReadOnly) | ||
| return -EROFS; | ||
| var ciphertextPath = GetCiphertextPath(path); | ||
| var ciphertextPath = GetCiphertextPathForUse(path); | ||
| if (ciphertextPath is null) | ||
| return -ENOENT; | ||
| @@ -259,7 +262,7 @@ public override unsafe int MkDir(ReadOnlySpan<byte> path, mode_t mode) | ||
| if (FuseOptions!.IsReadOnly) | ||
| return -EROFS; | ||
| var ciphertextPath = GetCiphertextPath(path); | ||
| var ciphertextPath = GetCiphertextPathForUse(path); | ||
| if (ciphertextPath is null) | ||
| return -ENOENT; | ||
| @@ -410,7 +413,7 @@ public override unsafe int Rename(ReadOnlySpan<byte> path, ReadOnlySpan<byte> ne | ||
| return -EROFS; | ||
| var ciphertextPath = GetCiphertextPath(path); | ||
| var newCiphertextPath = GetCiphertextPath(newPath); | ||
| var newCiphertextPath = GetCiphertextPathForUse(newPath); | ||
| if (ciphertextPath is null || newCiphertextPath is null) | ||
| return -ENOENT; | ||
| @@ -421,10 +424,15 @@ public override unsafe int Rename(ReadOnlySpan<byte> path, ReadOnlySpan<byte> ne | ||
| return -errno; | ||
| } | ||
| // Clean up old sidecar after successful rename | ||
| NativePathHelpers.DeleteSidecarFile( | ||
| Path.GetFileName(ciphertextPath), | ||
| Path.GetDirectoryName(ciphertextPath) ?? string.Empty); | ||
| return 0; | ||
| } | ||
| public override unsafe int RmDir(ReadOnlySpan<byte> path) | ||
| public override int RmDir(ReadOnlySpan<byte> path) | ||
| { | ||
| if (FuseOptions!.IsReadOnly) | ||
| return -EROFS; | ||
| @@ -437,17 +445,38 @@ public override unsafe int RmDir(ReadOnlySpan<byte> path) | ||
| return -ENOTEMPTY; | ||
| var directoryIdPath = Path.Combine(ciphertextPath, FileSystem.Constants.Names.DIRECTORY_ID_FILENAME); | ||
| // Remove DirectoryID | ||
| File.Delete(directoryIdPath); | ||
| specifics.DirectoryIdCache.CacheRemove(directoryIdPath); | ||
| fixed (byte *ciphertextPathPtr = Encoding.UTF8.GetBytes(ciphertextPath)) | ||
| try | ||
| { | ||
| if (rmdir(ciphertextPathPtr) == -1) | ||
| return -errno; | ||
| NativeRecycleBinHelpers.DeleteOrRecycle(ciphertextPath, specifics, StorableType.Folder); | ||
| } | ||
| catch (FileNotFoundException) | ||
| { | ||
| return -ENOENT; | ||
| } | ||
| catch (DirectoryNotFoundException) | ||
| { | ||
| return -ENOENT; | ||
| } | ||
| catch (UnauthorizedAccessException) | ||
| { | ||
| return -EACCES; | ||
| } | ||
| catch (IOException ioEx) when (ErrorHandlingHelpers.IsDiskFullException(ioEx)) | ||
| { | ||
| return -ENOSPC; | ||
| } | ||
| catch | ||
| { | ||
| return -EIO; | ||
| } | ||
| // Clean up sidecar after successful delete/recycle | ||
| NativePathHelpers.DeleteSidecarFile( | ||
| Path.GetFileName(ciphertextPath), | ||
| Path.GetDirectoryName(ciphertextPath) ?? string.Empty); | ||
| return 0; | ||
| } | ||
| @@ -529,7 +558,7 @@ public override int Truncate(ReadOnlySpan<byte> path, ulong length, FuseFileInfo | ||
| /// <remarks> | ||
| /// This method is also responsible for file deletion. | ||
| /// </remarks> | ||
| public override unsafe int Unlink(ReadOnlySpan<byte> path) | ||
| public override int Unlink(ReadOnlySpan<byte> path) | ||
| { | ||
| if (FuseOptions!.IsReadOnly) | ||
| return -EROFS; | ||
| @@ -541,11 +570,35 @@ public override unsafe int Unlink(ReadOnlySpan<byte> path) | ||
| if (Directory.Exists(ciphertextPath)) | ||
| return -EISDIR; | ||
| fixed (byte *ciphertextPathPtr = Encoding.UTF8.GetBytes(ciphertextPath)) | ||
| try | ||
| { | ||
| if (unlink(ciphertextPathPtr) == -1) | ||
| return -errno; | ||
| NativeRecycleBinHelpers.DeleteOrRecycle(ciphertextPath, specifics, StorableType.File); | ||
| } | ||
| catch (FileNotFoundException) | ||
| { | ||
| return -ENOENT; | ||
| } | ||
| catch (DirectoryNotFoundException) | ||
| { | ||
| return -ENOENT; | ||
| } | ||
| catch (UnauthorizedAccessException) | ||
| { | ||
| return -EACCES; | ||
| } | ||
| catch (IOException ioEx) when (ErrorHandlingHelpers.IsDiskFullException(ioEx)) | ||
| { | ||
| return -ENOSPC; | ||
| } | ||
| catch | ||
| { | ||
| return -EIO; | ||
| } | ||
d2dyno1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Clean up sidecar after successful delete/recycle | ||
| NativePathHelpers.DeleteSidecarFile( | ||
| Path.GetFileName(ciphertextPath), | ||
| Path.GetDirectoryName(ciphertextPath) ?? string.Empty); | ||
| return 0; | ||
| } | ||
| @@ -569,7 +622,7 @@ public override unsafe int UpdateTimestamps(ReadOnlySpan<byte> path, ref timespe | ||
| return -errno; | ||
| var result = futimens(*(int*)fd, times); | ||
| UnsafeNativeApis.CloseDir(fd); | ||
| CloseDir(fd); | ||
| if (result == -1) | ||
| return -errno; | ||
| @@ -614,12 +667,21 @@ public override int Write(ReadOnlySpan<byte> path, ulong offset, ReadOnlySpan<by | ||
| return buffer.Length; | ||
| } | ||
| protected override unsafe string? GetCiphertextPath(ReadOnlySpan<byte> plaintextName) | ||
| protected override unsafe string? GetCiphertextPath(ReadOnlySpan<byte> nativePlaintextName) | ||
| { | ||
| fixed (byte *plaintextNamePtr = nativePlaintextName) | ||
| { | ||
| var directoryId = new byte[FileSystem.Constants.DIRECTORY_ID_SIZE]; | ||
| return NativePathHelpers.GetCiphertextPath(Encoding.UTF8.GetString(plaintextNamePtr, nativePlaintextName.Length), specifics, directoryId); | ||
| } | ||
| } | ||
| private unsafe string? GetCiphertextPathForUse(ReadOnlySpan<byte> nativePlaintextName) | ||
| { | ||
| fixed (byte *plaintextNamePtr = plaintextName) | ||
| fixed (byte *plaintextNamePtr = nativePlaintextName) | ||
| { | ||
| var directoryId = new byte[FileSystem.Constants.DIRECTORY_ID_SIZE]; | ||
| return NativePathHelpers.GetCiphertextPath(Encoding.UTF8.GetString(plaintextNamePtr, plaintextName.Length), specifics, directoryId); | ||
| return NativePathHelpers.GetCiphertextPathForUse(Encoding.UTF8.GetString(plaintextNamePtr, nativePlaintextName.Length), specifics, directoryId); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15 src/Core/SecureFolderFS.Core.FileSystem/Exceptions/OrphanSidecarException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| namespace SecureFolderFS.Core.FileSystem.Exceptions | ||
| { | ||
| /// <summary> | ||
| /// Exception thrown when a sidecar file (.sffsi) exists without a matching shortened file (.sffsn). | ||
| /// </summary> | ||
| public sealed class OrphanSidecarException : Exception | ||
| { | ||
| public OrphanSidecarException(string sidecarName) | ||
| : base($"Orphan sidecar file has no matching shortened file: {sidecarName}") | ||
| { | ||
| } | ||
| } | ||
| } |
15 changes: 10 additions & 5 deletions
15 src/Core/SecureFolderFS.Core.FileSystem/Helpers/Health/HealthHelpers.Directory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.