import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.Vector;
import android.accounts.Account;
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
-
+ cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict());
+
boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath || fileExists(file.getFileId())) { // for renamed files; no more delete and create
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
+ cv.put(ProviderTableMeta.FILE_IN_CONFLICT, file.isInConflict());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
}
}
- private static boolean copyFile(File src, File target) {
+ private boolean copyFile(File src, File target) {
boolean ret = true;
InputStream in = null;
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
file.setDownloading(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
-
+ file.setInConflict(c.getInt(
+ c.getColumnIndex(ProviderTableMeta.FILE_IN_CONFLICT)) == 1 ? true : false);
+
}
return file;
}
ProviderTableMeta.FILE_IS_DOWNLOADING,
file.isDownloading() ? 1 : 0
);
+ cv.put(
+ ProviderTableMeta.FILE_IN_CONFLICT,
+ file.isInConflict() ? 1 : 0
+ );
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
}
+ public void saveConflict(OCFile file, boolean inConflict) {
+ ContentValues cv = new ContentValues();
+ cv.put(ProviderTableMeta.FILE_IN_CONFLICT, inConflict);
+ int updated = 0;
+ if (getContentResolver() != null) {
+ updated = getContentResolver().update(
+ ProviderTableMeta.CONTENT_URI_FILE,
+ cv,
+ ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(file.getFileId())}
+ );
+ } else {
+ try {
+ updated = getContentProviderClient().update(
+ ProviderTableMeta.CONTENT_URI_FILE,
+ cv,
+ ProviderTableMeta._ID + "=?",
+ new String[]{String.valueOf(file.getFileId())}
+ );
+ } catch (RemoteException e) {
+ Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage());
+ }
+ }
+
+ Log_OC.d(TAG, "Number of files updated with CONFLICT: " + updated);
+
+ if (updated > 0) {
+ if (inConflict) {
+ /// set conflict in all ancestor folders
+
+ long parentId = file.getParentId();
+ Set<String> ancestorIds = new HashSet<String>();
+ while (parentId != FileDataStorageManager.ROOT_PARENT_ID) {
+ ancestorIds.add(Long.toString(parentId));
+ parentId = getFileById(parentId).getParentId();
+ }
+
+ if (ancestorIds.size() > 0) {
+ StringBuffer whereBuffer = new StringBuffer();
+ whereBuffer.append(ProviderTableMeta._ID).append(" IN (");
+ for (int i = 0; i < ancestorIds.size() - 1; i++) {
+ whereBuffer.append("?,");
+ }
+ whereBuffer.append("?");
+ whereBuffer.append(")");
+
+ if (getContentResolver() != null) {
+ updated = getContentResolver().update(
+ ProviderTableMeta.CONTENT_URI_FILE,
+ cv,
+ whereBuffer.toString(),
+ ancestorIds.toArray(new String[]{})
+ );
+ } else {
+ try {
+ updated = getContentProviderClient().update(
+ ProviderTableMeta.CONTENT_URI_FILE,
+ cv,
+ whereBuffer.toString(),
+ ancestorIds.toArray(new String[]{})
+ );
+ } catch (RemoteException e) {
+ Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage());
+ }
+ }
+ } // else file is ROOT folder, no parent to set in conflict
+
+ } else {
+ /// TODO update conflict in ancestor folders
+ // (not directly unset; maybe there are more conflicts below them)
+ }
+ }
+
+ Log_OC.d(TAG, "Number of parents updated with CONFLICT: " + updated);
+
+ }
}