+ } catch (Exception e) {
+ Log_OC.e(TAG, "Exception upgrading account names or paths in database", e);
+ }
+ }
+
+
+ /**
+ * Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the
+ * table of files in database so that the paths to the local files keep being the same.
+ *
+ * @param db Database where table of files is included.
+ * @param newAccountName New name for the target OC account.
+ * @param oldAccountName Old name of the target OC account.
+ */
+ private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
+ String oldAccountName) {
+
+ String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
+ ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
+
+ Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
+ null,
+ whereClause,
+ new String[] { newAccountName },
+ null, null, null);
+
+ try {
+ if (c.moveToFirst()) {
+ // create storage path
+ String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
+ String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
+
+ // move files
+ File oldAccountFolder = new File(oldAccountPath);
+ File newAccountFolder = new File(newAccountPath);
+ oldAccountFolder.renameTo(newAccountFolder);
+
+ // update database
+ do {
+ // Update database
+ String oldPath = c.getString(
+ c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
+ OCFile file = new OCFile(
+ c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
+ String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
+
+ ContentValues cv = new ContentValues();
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
+ db.update(ProviderTableMeta.FILE_TABLE_NAME,
+ cv,
+ ProviderTableMeta.FILE_STORAGE_PATH + "=?",
+ new String[]{oldPath});
+
+ Log_OC.v("SQL", "Updated path of downloaded file: old file name == " + oldPath +
+ ", new file name == " + newPath);
+
+ } while (c.moveToNext());
+ }
+ } finally {
+ c.close();
+ }