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
7 changes: 7 additions & 0 deletions app/src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

/**
Expand All @@ -36,6 +37,12 @@ public void testCreateFolder() {
// folder exists
OCFile file = getStorageManager().getFileByPath(path);
assertTrue(file.isFolder());
assertEquals(path, file.getRemotePath());
assertNotNull(file.getLocalIdDirect());
assertEquals(
file.getLocalIdDirect(),
file.getRemoteId().substring(0, 8).replaceAll("^0*", "")
);

// cleanup
new RemoveFileOperation(file, false, account, false, targetContext, getStorageManager()).execute(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public boolean saveFile(OCFile ocFile) {
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, ocFile.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, ocFile.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, ocFile.getRemoteId());
cv.put(ProviderTableMeta.FILE_LOCAL_ID, ocFile.getLocalId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, ocFile.isUpdateThumbnailNeeded());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, ocFile.isDownloading());
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, ocFile.getEtagInConflict());
Expand Down Expand Up @@ -490,6 +491,7 @@ private ContentValues createContentValueForFile(OCFile folder) {
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
cv.put(ProviderTableMeta.FILE_LOCAL_ID, folder.getLocalId());
cv.put(ProviderTableMeta.FILE_FAVORITE, folder.isFavorite());
cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, folder.isEncrypted());
cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, folder.getUnreadCommentsCount());
Expand Down Expand Up @@ -524,6 +526,7 @@ private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_LOCAL_ID, file.getLocalId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
Expand Down Expand Up @@ -1014,6 +1017,7 @@ private OCFile createFileInstance(Cursor cursor) {
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
ocFile.setPermissions(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PERMISSIONS)));
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID)));
ocFile.setLocalId(getString(cursor, ProviderTableMeta.FILE_LOCAL_ID));
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
ocFile.setDownloading(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private String etagOnServer;
private boolean sharedViaLink;
private String permissions;
private String localId; // The fileid locally on server
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
private boolean updateThumbnailNeeded;
private boolean downloading;
Expand Down Expand Up @@ -149,6 +150,7 @@ private OCFile(Parcel source) {
sharedViaLink = source.readInt() == 1;
permissions = source.readString();
remoteId = source.readString();
localId = source.readString();
updateThumbnailNeeded = source.readInt() == 1;
downloading = source.readInt() == 1;
etagInConflict = source.readString();
Expand Down Expand Up @@ -182,6 +184,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(sharedViaLink ? 1 : 0);
dest.writeString(permissions);
dest.writeString(remoteId);
dest.writeString(localId);
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
dest.writeInt(downloading ? 1 : 0);
dest.writeString(etagInConflict);
Expand Down Expand Up @@ -447,6 +450,7 @@ private void resetData() {
sharedViaLink = false;
permissions = null;
remoteId = null;
localId = null;
updateThumbnailNeeded = false;
downloading = false;
etagInConflict = null;
Expand Down Expand Up @@ -550,7 +554,9 @@ public boolean isHidden() {
*/
@Nullable
public String getLocalId() {
if (getRemoteId() != null) {
if (localId != null) {
return localId;
} else if (getRemoteId() != null) {
return getRemoteId().substring(0, 8).replaceAll("^0*", "");
} else {
return null;
Expand Down Expand Up @@ -768,6 +774,10 @@ public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}

public void setLocalId(String localId) {
this.localId = localId;
}

public void setUpdateThumbnailNeeded(boolean updateThumbnailNeeded) {
this.updateThumbnailNeeded = updateThumbnailNeeded;
}
Expand Down Expand Up @@ -819,4 +829,9 @@ public void setSharees(List<ShareeUser> sharees) {
public void setRichWorkspace(String richWorkspace) {
this.richWorkspace = richWorkspace;
}

@VisibleForTesting
public String getLocalIdDirect() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInternalLocalId, or something like that, may be a better name.

return localId;
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 62;
public static final int DB_VERSION = 63;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -104,6 +104,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_SHARED_WITH_SHAREE = "shared_via_users";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_LOCAL_ID = "local_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_IS_DOWNLOADING = "is_downloading";
public static final String FILE_ETAG_IN_CONFLICT = "etag_in_conflict";
Expand Down Expand Up @@ -141,6 +142,7 @@ static public class ProviderTableMeta implements BaseColumns {
FILE_SHARED_WITH_SHAREE,
FILE_PERMISSIONS,
FILE_REMOTE_ID,
FILE_LOCAL_ID,
FILE_UPDATE_THUMBNAIL,
FILE_IS_DOWNLOADING,
FILE_ETAG_IN_CONFLICT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ private void createFilesTable(SQLiteDatabase db) {
+ ProviderTableMeta.FILE_SHARED_VIA_LINK + INTEGER
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
+ ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
+ ProviderTableMeta.FILE_LOCAL_ID + " TEXT null,"
+ ProviderTableMeta.FILE_UPDATE_THUMBNAIL + INTEGER //boolean
+ ProviderTableMeta.FILE_IS_DOWNLOADING + INTEGER //boolean
+ ProviderTableMeta.FILE_FAVORITE + INTEGER // boolean
Expand Down Expand Up @@ -2457,6 +2458,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if (oldVersion < 63 && newVersion >= 63) {
Log_OC.i(SQL, "Entering in the #63 add local id to files");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.FILE_LOCAL_ID + " TEXT ");

upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
Comment on lines +2476 to +2478

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of adding this between each upgrade if? It will print the same every time. Also, some upgrades set upgraded=true, but others don't. Looks like this needs cleanup, I will do it after this PR is merged

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public static OCFile fillOCFile(RemoteFile remote) {
file.setEtag(remote.getEtag());
file.setPermissions(remote.getPermissions());
file.setRemoteId(remote.getRemoteId());
file.setLocalId(remote.getLocalId());
file.setFavorite(remote.isFavorite());
if (file.isFolder()) {
file.setEncrypted(remote.isEncrypted());
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
daggerVersion = "2.41"
markwonVersion = "4.6.2"
prismVersion = "2.0.0"
androidLibraryVersion = "master-SNAPSHOT"
androidLibraryVersion = "fileId-SNAPSHOT"
mockitoVersion = "4.4.0"
mockitoKotlinVersion = "4.0.0"
mockkVersion = "1.12.3"
Expand Down