Compare commits

...
Author SHA1 Message Date
tobiasKaminsky 5ca15fd6ea fix deletion of folder in DB
Signed-off-by: tobiasKaminsky <[email protected]>
2025-06-20 07:48:29 +02:00
6 changed files with 79 additions and 4 deletions

No files matched your search

@@ -199,6 +199,23 @@ public class UploadIT extends AbstractOnServerIT {
uploadOCUpload(ocUpload);
}
@Test
public void testUploadInNonExistingParentFolder() {
createFolder(FOLDER + "2/3/4/");
assertTrue(new RemoveFileOperation(getStorageManager().getFileByPath(FOLDER),
false,
user,
false,
targetContext,
getStorageManager()
).execute(client).isSuccess());
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
FOLDER + "2/3/4/1.txt", account.name);
uploadOCUpload(ocUpload);
}
@Test
public void testUploadOnChargingOnlyButNotCharging() {
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
@@ -15,7 +15,9 @@ import org.junit.Test;
import java.io.IOException;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
public class RemoveFileOperationIT extends AbstractOnServerIT {
@@ -50,6 +52,50 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
getStorageManager())
.execute(client)
.isSuccess());
assertNull(getStorageManager().getFileByPath(parent));
assertNull(getStorageManager().getFileByPath(path));
assertNotNull(getStorageManager().getFileByPath("/"));
}
@Test
public void deleteOnlyParentFolder() {
// create some more data
createFolder("/test1/");
createFolder("/test2/");
String parent = "/test/";
String path = parent + "folder1/";
OCFile parentFolder = getStorageManager().getFileByPath(parent);
assertNull(parentFolder);
OCFile folder = getStorageManager().getFileByPath(path);
assertNull(folder);
createFolder(path);
folder = getStorageManager().getFileByPath(path);
assertNotNull(folder);
parentFolder = getStorageManager().getFileByPath(parent);
assertNotNull(parentFolder);
assertEquals(5, getStorageManager().getAllFiles().size());
assertTrue(new RemoveFileOperation(parentFolder,
false,
user,
false,
targetContext,
getStorageManager())
.execute(client)
.isSuccess());
assertNull(getStorageManager().getFileByPath(parent));
assertNull(getStorageManager().getFileByPath(path));
assertNotNull(getStorageManager().getFileByPath("/"));
assertEquals(3, getStorageManager().getAllFiles().size());
}
@Test
@@ -911,6 +911,7 @@ public class FileDataStorageManager {
// for recursive deletion
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
String[] whereArgs = new String[]{user.getAccountName(), folder.getRemotePath()};
int deleted = 0;
if (getContentProviderClient() != null) {
try {
@@ -102,10 +102,18 @@ public class RemoveFileOperation extends SyncOperation {
}
result = operation.execute(client);
if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, true, true));
if (fileToRemove.isFolder()) {
localRemovalFailed = !(getStorageManager().removeFolder(fileToRemove, true, true));
} else {
localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, true, true));
}
}
} else {
localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, false, true));
if (fileToRemove.isFolder()) {
localRemovalFailed = !(getStorageManager().removeFolder(fileToRemove, false, true));
} else {
localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, false, true));
}
if (!localRemovalFailed) {
result = new RemoteOperationResult(ResultCode.OK);
}
@@ -416,7 +416,6 @@ public class UploadFileOperation extends SyncOperation {
remoteParentPath = AutoRename.INSTANCE.rename(remoteParentPath, getCapabilities());
OCFile parent = getStorageManager().getFileByPath(remoteParentPath);
// in case of a fresh upload with subfolder, where parent does not exist yet
if (parent == null && (mFolderUnlockToken == null || mFolderUnlockToken.isEmpty())) {
// try to create folder
@@ -468,7 +468,11 @@ public class FileContentProvider extends ContentProvider {
// add ID to arguments if Uri has more than one segment
if (uriMatch != ROOT_DIRECTORY && uri.getPathSegments().size() > SINGLE_PATH_SEGMENT) {
String idColumn = uriMatch == DIRECTORY ? ProviderTableMeta.FILE_PARENT : ProviderTableMeta._ID;
selection = idColumn + "=? AND " + selection;
if (TextUtils.isEmpty(selection)) {
selection = idColumn + "=?";
} else {
selection = idColumn + "=? AND " + selection;
}
selectionArgs = VerificationUtils.prependUriFirstSegmentToSelectionArgs(selectionArgs, uri);
}