Skip to content

Commit

Permalink
Remove deleted files from metadata
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed May 2, 2024
1 parent 981d3dd commit 57b295c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.apache.jackrabbit.webdav.client.methods.DeleteMethod
* @param parentFolder parent folder
*/

@Suppress("LongParameterList")
class RemoveRemoteEncryptedFileOperation internal constructor(
private val remotePath: String,
private val user: User,
Expand All @@ -48,6 +49,8 @@ class RemoveRemoteEncryptedFileOperation internal constructor(
/**
* Performs the remove operation.
*/
@Deprecated("Deprecated in Java")
@Suppress("TooGenericExceptionCaught")
override fun run(client: OwnCloudClient): RemoteOperationResult<Void> {
val result: RemoteOperationResult<Void>
var delete: DeleteMethod? = null
Expand Down Expand Up @@ -110,9 +113,10 @@ class RemoveRemoteEncryptedFileOperation internal constructor(
}

private fun deleteForV1(client: OwnCloudClient, token: String?): Pair<RemoteOperationResult<Void>, DeleteMethod> {
@Suppress("DEPRECATION")
val arbitraryDataProvider: ArbitraryDataProvider = ArbitraryDataProviderImpl(context)
val publicKey = arbitraryDataProvider.getValue(user.accountName, EncryptionUtils.PUBLIC_KEY)
val privateKey = arbitraryDataProvider.getValue(user.accountName, EncryptionUtils.PRIVATE_KEY)
val publicKey = arbitraryDataProvider.getValue(user.accountName, EncryptionUtils.PUBLIC_KEY)

val (metadataExists, metadata) = EncryptionUtils.retrieveMetadataV1(
parentFolder,
Expand All @@ -125,6 +129,10 @@ class RemoveRemoteEncryptedFileOperation internal constructor(

val (result, delete) = deleteRemoteFile(client, token)

if (!isFolder) {
EncryptionUtils.removeFileFromMetadata(fileName, metadata)
}

val encryptedFolderMetadata = EncryptionUtils.encryptFolderMetadata(
metadata,
publicKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public static String serializeJSON(Object data, boolean excludeTransient) {
}
}

public static void removeFileFromMetadata(String fileName, DecryptedFolderMetadataFileV1 metadata) {
metadata.getFiles().remove(fileName);
}

public static String serializeJSON(Object data) {
return serializeJSON(data, false);
}
Expand Down

0 comments on commit 57b295c

Please sign in to comment.