Fixed check of modifications applied in server (still based on modification date)

This commit is contained in:
David A. Velasco 2012-12-05 16:14:01 +01:00
parent 4476c04736
commit abd5f51554
10 changed files with 61 additions and 11 deletions

View file

@ -108,6 +108,7 @@ public class FileDataStorageManager implements DataStorageManager {
boolean overriden = false;
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
@ -189,6 +190,7 @@ public class FileDataStorageManager implements DataStorageManager {
file = filesIt.next();
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
@ -414,6 +416,8 @@ public class FileDataStorageManager implements DataStorageManager {
.getColumnIndex(ProviderTableMeta.FILE_CREATION)));
file.setModificationTimestamp(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
file.setModificationTimestampAtLastSyncForData(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
file.setLastSyncDateForProperties(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
file.setLastSyncDateForData(c.getLong(c.

View file

@ -47,6 +47,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
private long mLength;
private long mCreationTimestamp;
private long mModifiedTimestamp;
private long mModifiedTimestampAtLastSyncForData;
private String mRemotePath;
private String mLocalPath;
private String mMimeType;
@ -84,6 +85,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mLength = source.readLong();
mCreationTimestamp = source.readLong();
mModifiedTimestamp = source.readLong();
mModifiedTimestampAtLastSyncForData = source.readLong();
mRemotePath = source.readString();
mLocalPath = source.readString();
mMimeType = source.readString();
@ -100,6 +102,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
dest.writeLong(mLength);
dest.writeLong(mCreationTimestamp);
dest.writeLong(mModifiedTimestamp);
dest.writeLong(mModifiedTimestampAtLastSyncForData);
dest.writeString(mRemotePath);
dest.writeString(mLocalPath);
dest.writeString(mMimeType);
@ -196,9 +199,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
}
/**
* Get a UNIX timestamp of the file modification time
*
* @return A UNIX timestamp of the modification time
* Get a UNIX timestamp of the file modification time.
*
* @return A UNIX timestamp of the modification time, corresponding to the value returned by the server
* in the last synchronization of the properties of this file.
*/
public long getModificationTimestamp() {
return mModifiedTimestamp;
@ -207,12 +211,40 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
/**
* Set a UNIX timestamp of the time the time the file was modified.
*
* To update with the value returned by the server in every synchronization of the properties
* of this file.
*
* @param modification_timestamp to set
*/
public void setModificationTimestamp(long modification_timestamp) {
mModifiedTimestamp = modification_timestamp;
}
/**
* Get a UNIX timestamp of the file modification time.
*
* @return A UNIX timestamp of the modification time, corresponding to the value returned by the server
* in the last synchronization of THE CONTENTS of this file.
*/
public long getModificationTimestampAtLastSyncForData() {
return mModifiedTimestampAtLastSyncForData;
}
/**
* Set a UNIX timestamp of the time the time the file was modified.
*
* To update with the value returned by the server in every synchronization of THE CONTENTS
* of this file.
*
* @param modification_timestamp to set
*/
public void setModificationTimestampAtLastSyncForData(long modificationTimestamp) {
mModifiedTimestampAtLastSyncForData = modificationTimestamp;
}
/**
* Returns the filename and "/" for the root directory
*
@ -280,6 +312,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mLength = 0;
mCreationTimestamp = 0;
mModifiedTimestamp = 0;
mModifiedTimestampAtLastSyncForData = 0;
mLastSyncDateForProperties = 0;
mLastSyncDateForData = 0;
mKeepInSync = false;

View file

@ -31,8 +31,7 @@ public class ProviderMeta {
public static final String AUTHORITY_FILES = "org.owncloud";
public static final String DB_FILE = "owncloud.db";
public static final String DB_NAME = "filelist";
//public static final int DB_VERSION = 2;
public static final int DB_VERSION = 3;
public static final int DB_VERSION = 4;
private ProviderMeta() {
}
@ -53,6 +52,7 @@ public class ProviderMeta {
public static final String FILE_NAME = "filename";
public static final String FILE_CREATION = "created";
public static final String FILE_MODIFIED = "modified";
public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data";
public static final String FILE_CONTENT_LENGTH = "content_length";
public static final String FILE_CONTENT_TYPE = "content_type";
public static final String FILE_STORAGE_PATH = "media_path";

View file

@ -301,6 +301,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
file.setLastSyncDateForProperties(syncDate);
file.setLastSyncDateForData(syncDate);
file.setModificationTimestamp(mCurrentDownload.getModificationTimestamp());
file.setModificationTimestampAtLastSyncForData(mCurrentDownload.getModificationTimestamp());
// file.setEtag(mCurrentDownload.getEtag()); // TODO Etag, where available
file.setMimetype(mCurrentDownload.getMimeType());
file.setStoragePath(mCurrentDownload.getSavePath());

View file

@ -489,7 +489,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
file.setCreationTimestamp(we.createTimestamp());
file.setFileLength(we.contentLength());
file.setMimetype(we.contentType());
file.setModificationTimestamp(we.modifiedTimesamp());
file.setModificationTimestamp(we.modifiedTimestamp());
file.setModificationTimestampAtLastSyncForData(we.modifiedTimestamp());
// file.setEtag(mCurrentDownload.getEtag()); // TODO Etag, where available
}

View file

@ -113,7 +113,7 @@ public class SynchronizeFileOperation extends RemoteOperation {
serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag())); // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged?
} else {
// server without etags
serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestamp());
serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestampAtLastSyncForData());
}
boolean localChanged = (mLocalChangeAlreadyKnown || mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData());
// TODO this will be always true after the app is upgraded to database version 3; will result in unnecessary uploads
@ -214,7 +214,7 @@ public class SynchronizeFileOperation extends RemoteOperation {
file.setCreationTimestamp(we.createTimestamp());
file.setFileLength(we.contentLength());
file.setMimetype(we.contentType());
file.setModificationTimestamp(we.modifiedTimesamp());
file.setModificationTimestamp(we.modifiedTimestamp());
return file;
}

View file

@ -279,7 +279,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
file.setCreationTimestamp(we.createTimestamp());
file.setFileLength(we.contentLength());
file.setMimetype(we.contentType());
file.setModificationTimestamp(we.modifiedTimesamp());
file.setModificationTimestamp(we.modifiedTimestamp());
file.setParentId(mParentId);
return file;
}

View file

@ -310,6 +310,7 @@ public class UploadFileOperation extends RemoteOperation {
newFile.setFileLength(mFile.getFileLength());
newFile.setMimetype(mFile.getMimetype());
newFile.setModificationTimestamp(mFile.getModificationTimestamp());
newFile.setModificationTimestampAtLastSyncForData(mFile.getModificationTimestampAtLastSyncForData());
// newFile.setEtag(mFile.getEtag())
newFile.setKeepInSync(mFile.keepInSync());
newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties());

View file

@ -62,6 +62,8 @@ public class FileContentProvider extends ContentProvider {
ProviderTableMeta.FILE_CREATION);
mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED,
ProviderTableMeta.FILE_MODIFIED);
mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA);
mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH,
ProviderTableMeta.FILE_CONTENT_LENGTH);
mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE,
@ -224,7 +226,8 @@ public class FileContentProvider extends ContentProvider {
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, "
+ ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, "
+ ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, "
+ ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER );"
+ ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, "
+ ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER );"
);
}
@ -246,6 +249,13 @@ public class FileContentProvider extends ContentProvider {
" DEFAULT 0");
upgraded = true;
}
if (oldVersion < 4 && newVersion >= 4) {
Log.i("SQL", "Entering in the #3 ADD in onUpgrade");
db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
" ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER " +
" DEFAULT 0");
upgraded = true;
}
if (!upgraded)
Log.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
}

View file

@ -126,7 +126,7 @@ public class WebdavEntry {
return mCreateTimestamp;
}
public long modifiedTimesamp() {
public long modifiedTimestamp() {
return mModifiedTimestamp;
}