Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import com.nextcloud.model.ShareeEntry;
import com.nextcloud.utils.date.DateFormatPattern;
import com.nextcloud.utils.extensions.DateExtensionsKt;
import com.nextcloud.utils.extensions.FileExtensionsKt;
import com.nextcloud.utils.extensions.StringExtensionsKt;
import com.owncloud.android.MainApp;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.network.WebdavEntry;
Expand Down Expand Up @@ -913,25 +915,31 @@ public boolean removeFile(OCFile ocFile, boolean removeDBData, boolean removeLoc
}

private boolean removeLocalCopyIfNeeded(OCFile ocFile, boolean removeLocalCopy, boolean removeDBData) {
String localPath = ocFile.getStoragePath();

if (!removeLocalCopy) {
Log_OC.d(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false");
Log_OC.w(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false");
return true;
}

if (!ocFile.isDown()) {
Log_OC.d(TAG, "removeLocalCopyIfNeeded: file not downloaded -> skip");
String localPath = ocFile.getStoragePath();
final var file = FileExtensionsKt.toFile(localPath);
if (file == null) {
Log_OC.w(TAG, "removeLocalCopyIfNeeded: file exists -> skip");
return true;
}

if (localPath == null) {
Log_OC.d(TAG, "removeLocalCopyIfNeeded: localPath is null -> skip");
if (ocFile.isFolder()) {
Log_OC.w(TAG, "removeLocalCopyIfNeeded: file is folder -> skip");
return true;
}

Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath);
String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile);
if (!localPath.equalsIgnoreCase(expectedPath)) {
Log_OC.w(TAG, "removeLocalCopyIfNeeded: Path mismatch! Expected " + expectedPath
+ " but found " + localPath + ". Skipping deletion to prevent data loss.");
return true;
}

Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath);
boolean success = new File(localPath).delete();
Log_OC.d(TAG, "removeLocalCopyIfNeeded: file deletion result=" + success);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public static String getSavePath(String accountName) {
* Get local path where OCFile file is to be stored after upload. That is,
* corresponding local path (in local owncloud storage) to remote uploaded
* file.
* <p>
* e.g. /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/admin@example.cloud/folder/file.txt
*/
public static String getDefaultSavePathFor(String accountName, OCFile file) {
return getSavePath(accountName) + file.getDecryptedRemotePath();
Expand Down
Loading