|
48 | 48 | import com.nextcloud.model.ShareeEntry; |
49 | 49 | import com.nextcloud.utils.date.DateFormatPattern; |
50 | 50 | import com.nextcloud.utils.extensions.DateExtensionsKt; |
| 51 | +import com.nextcloud.utils.extensions.FileExtensionsKt; |
| 52 | +import com.nextcloud.utils.extensions.StringExtensionsKt; |
51 | 53 | import com.owncloud.android.MainApp; |
52 | 54 | import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; |
53 | 55 | import com.owncloud.android.lib.common.network.WebdavEntry; |
@@ -913,25 +915,31 @@ public boolean removeFile(OCFile ocFile, boolean removeDBData, boolean removeLoc |
913 | 915 | } |
914 | 916 |
|
915 | 917 | private boolean removeLocalCopyIfNeeded(OCFile ocFile, boolean removeLocalCopy, boolean removeDBData) { |
916 | | - String localPath = ocFile.getStoragePath(); |
917 | | - |
918 | 918 | if (!removeLocalCopy) { |
919 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false"); |
| 919 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false"); |
920 | 920 | return true; |
921 | 921 | } |
922 | 922 |
|
923 | | - if (!ocFile.isDown()) { |
924 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: file not downloaded -> skip"); |
| 923 | + String localPath = ocFile.getStoragePath(); |
| 924 | + final var file = FileExtensionsKt.toFile(localPath); |
| 925 | + if (file == null) { |
| 926 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: file exists -> skip"); |
925 | 927 | return true; |
926 | 928 | } |
927 | 929 |
|
928 | | - if (localPath == null) { |
929 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: localPath is null -> skip"); |
| 930 | + if (ocFile.isFolder()) { |
| 931 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: file is folder -> skip"); |
930 | 932 | return true; |
931 | 933 | } |
932 | 934 |
|
933 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath); |
| 935 | + String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile); |
| 936 | + if (!localPath.equalsIgnoreCase(expectedPath)) { |
| 937 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: Path mismatch! Expected " + expectedPath |
| 938 | + + " but found " + localPath + ". Skipping deletion to prevent data loss."); |
| 939 | + return true; |
| 940 | + } |
934 | 941 |
|
| 942 | + Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath); |
935 | 943 | boolean success = new File(localPath).delete(); |
936 | 944 | Log_OC.d(TAG, "removeLocalCopyIfNeeded: file deletion result=" + success); |
937 | 945 |
|
|
0 commit comments