Clear temp directory for cancelling all uploads

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-11 16:55:35 +02:00 committed by Alper Öztürk
parent 39e9916732
commit 7470fef2d6
3 changed files with 45 additions and 10 deletions

View file

@ -56,7 +56,10 @@ import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeType;
import com.owncloud.android.utils.MimeTypeUtil;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -338,6 +341,43 @@ public class FileDataStorageManager {
return ocFile;
}
private static final String tempEncryptedFolderPath = "temp_encrypted_folder";
public static void clearTempEncryptedFolder(Context context) {
File tempEncryptedFolder = getTempEncryptedFolder(context);
if (!tempEncryptedFolder.exists()) {
Log_OC.d(TAG,"tempEncryptedFolder not exists");
return;
}
try {
FileUtils.cleanDirectory(tempEncryptedFolder);
Log_OC.d(TAG,"tempEncryptedFolder cleared");
} catch (IOException exception) {
Log_OC.d(TAG,"Error caught at clearTempEncryptedFolder: " + exception);
}
}
public static File getTempEncryptedFolder(Context context) {
String dirPath = context.getFilesDir().getAbsolutePath() + File.separator + tempEncryptedFolderPath;
return new File(dirPath);
}
public static File createTempEncryptedFolder(Context context) {
File tempEncryptedFolder = getTempEncryptedFolder(context);
if (!tempEncryptedFolder.exists()) {
boolean isTempEncryptedFolderCreated = tempEncryptedFolder.mkdirs();
Log_OC.d(TAG, "tempEncryptedFolder created" + isTempEncryptedFolderCreated);
} else {
Log_OC.d(TAG, "tempEncryptedFolder already exists");
}
return tempEncryptedFolder;
}
public void saveNewFile(OCFile newFile) {
String remoteParentPath = new File(newFile.getRemotePath()).getParent();
remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?

View file

@ -54,6 +54,8 @@ import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Arrays;
import java.util.Optional;
@ -169,6 +171,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
if (itemId == R.id.action_upload_list_cancelled_clear) {
uploadsStorageManager.clearCancelledUploadsForCurrentAccount();
loadUploadItemsFromDb();
FileDataStorageManager.clearTempEncryptedFolder(parentActivity);
} else if (itemId == R.id.action_upload_list_cancelled_resume) {
retryCancelledUploads();
}

View file

@ -548,16 +548,7 @@ public final class EncryptionUtils {
}
public static EncryptedFile encryptFile(Context context, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
String dirPath = context.getFilesDir().getAbsolutePath() + File.separator + "temp_encrypted_folder";
File tempEncryptedFolder = new File(dirPath);
if (!tempEncryptedFolder.exists()) {
boolean isTempEncryptedFolderCreated = tempEncryptedFolder.mkdirs();
Log_OC.d(TAG, "tempEncryptedFolder created" + isTempEncryptedFolderCreated);
} else {
Log_OC.d(TAG, "tempEncryptedFolder already exists");
}
File tempEncryptedFolder = FileDataStorageManager.createTempEncryptedFolder(context);
File tempEncryptedFile = File.createTempFile(file.getName(), null, tempEncryptedFolder);
encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
String authenticationTagString = getAuthenticationTag(cipher);