Skip to content
Closed
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
20 changes: 15 additions & 5 deletions library/src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
*/
package com.owncloud.android;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.net.Uri;

import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand All @@ -43,10 +47,6 @@
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Tests related to file operations
*/
Expand All @@ -59,7 +59,17 @@ public void testCreateFolderSuccess() {
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());

// verify folder
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
RemoteOperationResult result = new ReadFolderRemoteOperation(path).execute(client);
assertTrue(result.isSuccess());

RemoteFile folder = (RemoteFile) result.getData().get(0);
assertEquals(path, folder.getRemotePath());
assertNotNull(folder.getLocalId());
assertEquals(
folder.getLocalId(),
folder.getRemoteId().substring(0, 8).replaceAll("^0*", "")
);


// remove folder
assertTrue(new RemoveFileRemoteOperation(path).execute(client).isSuccess());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@

import javax.annotation.Nullable;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.Getter;
import lombok.Setter;

public class WebdavEntry {

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

public static final String NAMESPACE_OC = "http://owncloud.org/ns";
public static final String NAMESPACE_NC = "http://nextcloud.org/ns";
public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions";
public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id";
public static final String NAMESPACE_OC = "http://owncloud.org/ns";
public static final String NAMESPACE_NC = "http://nextcloud.org/ns";
public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions";
public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id";
public static final String EXTENDED_PROPERTY_NAME_FILE_ID = "fileid";
public static final String EXTENDED_PROPERTY_NAME_SIZE = "size";
public static final String EXTENDED_PROPERTY_FAVORITE = "favorite";
public static final String EXTENDED_PROPERTY_IS_ENCRYPTED = "is-encrypted";
Expand Down Expand Up @@ -90,6 +92,7 @@ public class WebdavEntry {
@Getter private String eTag;
@Getter private String permissions;
@Getter private String remoteId;
@Getter private String localId;
@Getter private String trashbinOriginalLocation;
@Getter private String trashbinFilename;
@Getter private long trashbinDeletionTimestamp;
Expand All @@ -116,12 +119,13 @@ public class WebdavEntry {

public enum MountType {INTERNAL, EXTERNAL, GROUP}

@SuppressFBWarnings("STT_TOSTRING_STORED_IN_FIELD")
public WebdavEntry(MultiStatusResponse ms, String splitElement) {
resetData();

Namespace ocNamespace = Namespace.getNamespace(NAMESPACE_OC);
Namespace ncNamespace = Namespace.getNamespace(NAMESPACE_NC);

if (ms.getStatus().length != 0) {
uri = ms.getHref();

Expand All @@ -137,8 +141,7 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) {
if (prop != null) {
name = prop.getName().toString();
name = name.substring(1, name.length() - 1);
}
else {
} else {
String[] tmp = path.split("/");
if (tmp.length > 0)
name = tmp[tmp.length - 1];
Expand All @@ -160,17 +163,17 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) {
}
}
}

// check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3
// {DAV:}resourcetype
prop = propSet.get(DavPropertyName.RESOURCETYPE);
if (prop!= null) {
Object value = prop.getValue();
if (value != null) {
contentType = "DIR"; // a specific attribute would be better,
// but this is enough;
// unless while we have no reason to distinguish
// MIME types for folders
// but this is enough;
// unless while we have no reason to distinguish
// MIME types for folders
}
}

Expand Down Expand Up @@ -254,6 +257,12 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) {
remoteId = prop.getValue().toString();
}

// OC remote id property <oc:fileid>
prop = propSet.get(EXTENDED_PROPERTY_NAME_FILE_ID, ocNamespace);
if (prop != null) {
localId = prop.getValue().toString();
}

// OC size property <oc:size>
prop = propSet.get(EXTENDED_PROPERTY_NAME_SIZE, ocNamespace);
if (prop != null) {
Expand Down Expand Up @@ -323,7 +332,7 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) {
} else {
hasPreview = true;
}

// NC trashbin-original-location <nc:trashbin-original-location>
prop = propSet.get(TRASHBIN_ORIGINAL_LOCATION, ncNamespace);
if (prop != null) {
Expand Down Expand Up @@ -368,7 +377,7 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) {
ArrayList list = (ArrayList) prop.getValue();

List<ShareeUser> tempList = new ArrayList<>();

for (int i = 0; i < list.size(); i++) {
Element element = (Element) list.get(i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import android.net.Uri;

import androidx.annotation.Nullable;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
Expand All @@ -40,6 +38,8 @@
import java.util.Date;
import java.util.Locale;

import androidx.annotation.Nullable;

public class WebdavUtils {
private static final SimpleDateFormat DATETIME_FORMATS[] = {
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US),
Expand Down Expand Up @@ -103,6 +103,7 @@ public static DavPropertyNameSet getAllPropSet() {
propSet.add(DavPropertyName.GETETAG);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_FILE_ID, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, ncNamespace);
Expand Down Expand Up @@ -138,6 +139,7 @@ public static DavPropertyNameSet getFilePropSet() {
propSet.add(DavPropertyName.GETETAG);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_FILE_ID, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_HAS_PREVIEW, ncNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private RemoteFile fillOCFile(WebdavEntry we) {
file.setEtag(we.getETag());
file.setPermissions(we.getPermissions());
file.setRemoteId(we.getRemoteId());
file.setLocalId(we.getLocalId());
file.setSize(we.getSize());
file.setFavorite(we.isFavorite());
file.setEncrypted(we.isEncrypted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class RemoteFile implements Parcelable, Serializable {
private String etag;
private String permissions;
private String remoteId;
private String localId;
private long size;
private boolean favorite;
private boolean encrypted;
Expand Down Expand Up @@ -100,6 +101,7 @@ public RemoteFile(WebdavEntry we) {
setEtag(we.getETag());
setPermissions(we.getPermissions());
setRemoteId(we.getRemoteId());
setLocalId(we.getLocalId());
setSize(we.getSize());
setFavorite(we.isFavorite());
setEncrypted(we.isEncrypted());
Expand All @@ -125,6 +127,7 @@ private void resetData() {
etag = null;
permissions = null;
remoteId = null;
localId = null;
size = 0;
favorite = false;
encrypted = false;
Expand Down Expand Up @@ -168,6 +171,7 @@ public void readFromParcel(Parcel source) {
etag = source.readString();
permissions = source.readString();
remoteId = source.readString();
localId = source.readString();
size = source.readLong();
favorite = Boolean.parseBoolean(source.readString());
encrypted = Boolean.parseBoolean(source.readString());
Expand All @@ -194,6 +198,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(etag);
dest.writeString(permissions);
dest.writeString(remoteId);
dest.writeString(localId);
dest.writeLong(size);
dest.writeString(Boolean.toString(favorite));
dest.writeString(Boolean.toString(encrypted));
Expand All @@ -204,10 +209,4 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(note);
dest.writeParcelableArray(sharees, 0);
}

@SuppressFBWarnings(value = "STT_STRING_PARSING_A_FIELD", justification = "remoteId contains cloud id and local id")
public String getLocalId() {
return remoteId.substring(0, 8).replaceAll("^0*", "");
}

}
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170
163