X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b27ebf0310b2355cdd825c43b995e12688ae3df0..ac6b3d25ac71cf9bf01bcdb00eb43745af96ffb9:/src/com/owncloud/android/datamodel/FileDataStorageManager.java diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 1f7ee4c3..a8186cd5 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -145,6 +145,29 @@ public class FileDataStorageManager implements DataStorageManager { + e.getMessage()); } } + } else if (fileExists(file.getFileId())) { // for renamed files; no more delete and create + OCFile oldFile = getFileById(file.getFileId()); + if (file.getStoragePath() == null && oldFile.getStoragePath() != null) + file.setStoragePath(oldFile.getStoragePath()); + if (!file.isDirectory()); + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); + + overriden = true; + if (getContentResolver() != null) { + getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, + ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(file.getFileId()) }); + } else { + try { + getContentProvider().update(ProviderTableMeta.CONTENT_URI, + cv, ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(file.getFileId()) }); + } catch (RemoteException e) { + Log.e(TAG, + "Fail to insert insert file to database " + + e.getMessage()); + } + } } else { Uri result_uri = null; if (getContentResolver() != null) { @@ -201,11 +224,12 @@ public class FileDataStorageManager implements DataStorageManager { cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0); if (fileExists(file.getRemotePath())) { - OCFile tmpfile = getFileByPath(file.getRemotePath()); - file.setStoragePath(tmpfile.getStoragePath()); + OCFile oldFile = getFileByPath(file.getRemotePath()); + if (file.getStoragePath() == null && oldFile.getStoragePath() != null) + file.setStoragePath(oldFile.getStoragePath()); if (!file.isDirectory()); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); - file.setFileId(tmpfile.getFileId()); + file.setFileId(oldFile.getFileId()); operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). withValues(cv). @@ -213,6 +237,19 @@ public class FileDataStorageManager implements DataStorageManager { new String[] { String.valueOf(file.getFileId()) }) .build()); + } else if (fileExists(file.getFileId())) { + OCFile oldFile = getFileById(file.getFileId()); + if (file.getStoragePath() == null && oldFile.getStoragePath() != null) + file.setStoragePath(oldFile.getStoragePath()); + if (!file.isDirectory()); + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); + + operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). + withValues(cv). + withSelection( ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(file.getFileId()) }) + .build()); + } else { operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build()); }