1515using SecureFolderFS . Storage . Extensions ;
1616using SecureFolderFS . Storage . Recyclable ;
1717using SecureFolderFS . Storage . Renamable ;
18+ using SecureFolderFS . Storage . VirtualFileSystem ;
1819
1920namespace SecureFolderFS . Core . FileSystem . Storage
2021{
@@ -43,6 +44,9 @@ public CryptoFolder(string plaintextId, IFolder inner, FileSystemSpecifics speci
4344 /// <inheritdoc/>
4445 public virtual async Task < IStorableChild > RenameAsync ( IStorableChild storable , string newName , CancellationToken cancellationToken = default )
4546 {
47+ if ( specifics . Options . IsReadOnly )
48+ throw FileSystemExceptions . FileSystemReadOnly ;
49+
4650 if ( Inner is not IRenamableFolder renamableFolder )
4751 throw new NotSupportedException ( "Renaming folder contents is not supported." ) ;
4852
@@ -112,6 +116,9 @@ public virtual async Task DeleteAsync(IStorableChild item, CancellationToken can
112116 /// <inheritdoc/>
113117 public virtual async Task DeleteAsync ( IStorableChild item , long sizeHint = - 1L , bool deleteImmediately = false , CancellationToken cancellationToken = default )
114118 {
119+ if ( specifics . Options . IsReadOnly )
120+ throw FileSystemExceptions . FileSystemReadOnly ;
121+
115122 if ( Inner is not IModifiableFolder modifiableFolder )
116123 throw new NotSupportedException ( "Modifying folder contents is not supported." ) ;
117124
@@ -138,10 +145,13 @@ public virtual async Task DeleteAsync(IStorableChild item, long sizeHint = -1L,
138145 /// <inheritdoc/>
139146 public virtual async Task < IChildFolder > CreateFolderAsync ( string name , bool overwrite = false , CancellationToken cancellationToken = default )
140147 {
148+ if ( specifics . Options . IsReadOnly )
149+ throw FileSystemExceptions . FileSystemReadOnly ;
150+
141151 if ( Inner is not IModifiableFolder modifiableFolder )
142152 throw new NotSupportedException ( "Modifying folder contents is not supported." ) ;
143153
144- var encryptedName = await AbstractPathHelpers . EncryptNameAsync ( name , Inner , specifics , cancellationToken ) ;
154+ var encryptedName = await AbstractPathHelpers . EncryptNameForUseAsync ( name , Inner , specifics , cancellationToken ) ;
145155 var folder = await modifiableFolder . CreateFolderAsync ( encryptedName , overwrite , cancellationToken ) ;
146156 if ( folder is not IModifiableFolder createdModifiableFolder )
147157 throw new ArgumentException ( "The created folder is not modifiable." ) ;
@@ -163,10 +173,13 @@ public virtual async Task<IChildFolder> CreateFolderAsync(string name, bool over
163173 /// <inheritdoc/>
164174 public virtual async Task < IChildFile > CreateFileAsync ( string name , bool overwrite = false , CancellationToken cancellationToken = default )
165175 {
176+ if ( specifics . Options . IsReadOnly )
177+ throw FileSystemExceptions . FileSystemReadOnly ;
178+
166179 if ( Inner is not IModifiableFolder modifiableFolder )
167180 throw new NotSupportedException ( "Modifying folder contents is not supported." ) ;
168181
169- var encryptedName = await AbstractPathHelpers . EncryptNameAsync ( name , Inner , specifics , cancellationToken ) ;
182+ var encryptedName = await AbstractPathHelpers . EncryptNameForUseAsync ( name , Inner , specifics , cancellationToken ) ;
170183 var file = await modifiableFolder . CreateFileAsync ( encryptedName , overwrite , cancellationToken ) ;
171184
172185 return ( IChildFile ) Wrap ( file , name ) ;
@@ -183,6 +196,9 @@ public virtual Task<IChildFile> CreateCopyOfAsync(IFile fileToCopy, bool overwri
183196 public virtual async Task < IChildFile > CreateCopyOfAsync ( IFile fileToCopy , bool overwrite , string newName , CancellationToken cancellationToken ,
184197 CreateRenamedCopyOfDelegate fallback )
185198 {
199+ if ( specifics . Options . IsReadOnly )
200+ throw FileSystemExceptions . FileSystemReadOnly ;
201+
186202 if ( Inner is not IModifiableFolder )
187203 throw new NotSupportedException ( "Modifying folder contents is not supported." ) ;
188204
@@ -195,7 +211,7 @@ public virtual async Task<IChildFile> CreateCopyOfAsync(IFile fileToCopy, bool o
195211 return await fallback ( this , fileToCopy , overwrite , newName , cancellationToken ) ;
196212
197213 // Encrypt the new name
198- var ciphertextNewName = await AbstractPathHelpers . EncryptNameAsync ( newName , Inner , specifics , cancellationToken ) ;
214+ var ciphertextNewName = await AbstractPathHelpers . EncryptNameForUseAsync ( newName , Inner , specifics , cancellationToken ) ;
199215
200216 // Copy the ciphertext file
201217 var copiedCiphertextFile = await createRenamedCopyOf . CreateCopyOfAsync ( ciphertextFileToCopy , overwrite , ciphertextNewName , cancellationToken ) ;
@@ -213,6 +229,9 @@ public virtual Task<IChildFile> MoveFromAsync(IChildFile fileToMove, IModifiable
213229 public virtual async Task < IChildFile > MoveFromAsync ( IChildFile fileToMove , IModifiableFolder source , bool overwrite , string newName ,
214230 CancellationToken cancellationToken , MoveRenamedFromDelegate fallback )
215231 {
232+ if ( specifics . Options . IsReadOnly )
233+ throw FileSystemExceptions . FileSystemReadOnly ;
234+
216235 if ( Inner is not IModifiableFolder )
217236 throw new NotSupportedException ( "Modifying folder contents is not supported." ) ;
218237
@@ -231,7 +250,7 @@ public virtual async Task<IChildFile> MoveFromAsync(IChildFile fileToMove, IModi
231250 return await fallback ( this , fileToMove , source , overwrite , newName , cancellationToken ) ;
232251
233252 // Encrypt the new name
234- var newCiphertextName = await AbstractPathHelpers . EncryptNameAsync ( newName , Inner , specifics , cancellationToken ) ;
253+ var newCiphertextName = await AbstractPathHelpers . EncryptNameForUseAsync ( newName , Inner , specifics , cancellationToken ) ;
235254
236255 // Move the ciphertext file
237256 var movedCiphertextFile = await moveRenamedFrom . MoveFromAsync ( ciphertextFileToMove , ciphertextSourceModifiableFolder , overwrite , newCiphertextName , cancellationToken , fallback ) ;
0 commit comments