Skip to content

Commit

Permalink
Merge pull request #1201 from nextcloud/createFolderRemoteId
Browse files Browse the repository at this point in the history
Really use remoteId
  • Loading branch information
tobiasKaminsky authored Sep 25, 2023
2 parents 1d0a747 + 905b22b commit 55aebde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void setUp() {
public void testCreateFolder() {
String remotePath = mFullPath2FolderBase;
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult<Long> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());

// Create Subfolder
Expand All @@ -89,13 +89,13 @@ public void testCreateFolder() {
public void testFileID() {
String remotePath = mFullPath2FolderBase + "/" + RandomStringGenerator.make(TAG_LENGTH);
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult<Long> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());

RemoteOperationResult readResult = new ReadFileRemoteOperation(remotePath).execute(client);
assertTrue(readResult.isSuccess());

Long remoteId = ((RemoteFile) readResult.getData().get(0)).getLocalId();
String remoteId = ((RemoteFile) readResult.getData().get(0)).getRemoteId();
assertEquals(result.getResultData(), remoteId);
}

Expand All @@ -106,7 +106,7 @@ public void testFileID() {
@Test
public void testCreateFolderSpecialCharactersOnNewVersion() {
String remotePath = mFullPath2FolderBase + "_<";
RemoteOperationResult<Long> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());

remotePath = mFullPath2FolderBase + "_>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author David A. Velasco
* @author masensio
*/
public class CreateFolderRemoteOperation extends RemoteOperation<Long> {
public class CreateFolderRemoteOperation extends RemoteOperation<String> {

private static final String TAG = CreateFolderRemoteOperation.class.getSimpleName();

Expand Down Expand Up @@ -77,8 +77,8 @@ public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, St
* @param client Client object to communicate with the remote ownCloud server.
*/
@Override
protected RemoteOperationResult<Long> run(OwnCloudClient client) {
RemoteOperationResult<Long> result;
protected RemoteOperationResult<String> run(OwnCloudClient client) {
RemoteOperationResult<String> result;

result = createFolder(client);
if (!result.isSuccess() && createFullPath &&
Expand All @@ -94,8 +94,8 @@ protected RemoteOperationResult<Long> run(OwnCloudClient client) {
}


private RemoteOperationResult<Long> createFolder(OwnCloudClient client) {
RemoteOperationResult<Long> result;
private RemoteOperationResult<String> createFolder(OwnCloudClient client) {
RemoteOperationResult<String> result;
MkColMethod mkCol = null;
try {
mkCol = new MkColMethod(client.getFilesDavUri(remotePath));
Expand All @@ -114,11 +114,9 @@ private RemoteOperationResult<Long> createFolder(OwnCloudClient client) {
Header cookieHeader = mkCol.getResponseHeader("Set-Cookie");

if (fileIdHeader != null && cookieHeader != null) {
String instanceId = cookieHeader.getValue().split("=")[0];
String fileId = fileIdHeader.getValue();
String id = fileId.replace(instanceId, "");

result.setResultData(Long.valueOf(id));
result.setResultData(fileId);
} else {
result.setResultData(null);
}
Expand All @@ -137,8 +135,8 @@ private RemoteOperationResult<Long> createFolder(OwnCloudClient client) {
return result;
}

private RemoteOperationResult<Long> createParentFolder(String parentPath, OwnCloudClient client) {
RemoteOperation<Long> operation = new CreateFolderRemoteOperation(parentPath, createFullPath);
private RemoteOperationResult<String> createParentFolder(String parentPath, OwnCloudClient client) {
RemoteOperation<String> operation = new CreateFolderRemoteOperation(parentPath, createFullPath);
return operation.execute(client);
}

Expand Down

0 comments on commit 55aebde

Please sign in to comment.