Changes in update for downloaded files

This commit is contained in:
masensio 2015-04-15 18:37:12 +02:00
parent 123c7fc1cd
commit ab7c998d07

View file

@ -888,7 +888,6 @@ public class FileContentProvider extends ContentProvider {
String oldAccountName) { String oldAccountName) {
boolean upgradedResult = true; boolean upgradedResult = true;
boolean upgraded = false; boolean upgraded = false;
boolean renamedResult = true;
boolean renamed = false; boolean renamed = false;
String selectQuery = "SELECT " + ProviderTableMeta._ID + " FROM " + String selectQuery = "SELECT " + ProviderTableMeta._ID + " FROM " +
@ -903,11 +902,12 @@ public class FileContentProvider extends ContentProvider {
String newAccountPath = FileStorageUtils.getSavePath(newAccountName); String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
if (oldAccountPath != newAccountPath) { if (oldAccountPath != newAccountPath) {
// move files
File oldAccountFolder = new File(oldAccountPath);
File newAccountFolder = new File(newAccountPath); File newAccountFolder = new File(newAccountPath);
if (!newAccountFolder.exists()) { renamed = oldAccountFolder.renameTo(newAccountFolder);
newAccountFolder.mkdirs();
} // update database
// update file and database
do { do {
// Update database // Update database
String oldPath = c.getString( String oldPath = c.getString(
@ -936,27 +936,26 @@ public class FileContentProvider extends ContentProvider {
} }
upgradedResult = upgraded && upgradedResult; upgradedResult = upgraded && upgradedResult;
// move file // // move file
File oldFile = new File(oldPath); // File oldFile = new File(oldPath);
renamed = false; // renamed = false;
if (oldFile.exists()) { // if (oldFile.exists()) {
File newFile = new File(newPath); // File newFile = new File(newPath);
File newFolder = newFile.getParentFile(); // File newFolder = newFile.getParentFile();
if (!newFolder.exists()) { // if (!newFolder.exists()) {
newFolder.mkdirs(); // newFolder.mkdirs();
} // }
renamed = newFile.renameTo(newFile); // renamed = oldFile.renameTo(newFile);
} // }
renamedResult = renamed && renamedResult;
} while (c.moveToNext()); } while (c.moveToNext());
// remove old folder // // remove old folder
if (renamed && upgradedResult) { // if (renamed && upgradedResult) {
File oldAccountFolder = new File(oldAccountPath); // File oldAccountFolder = new File(oldAccountPath);
if (oldAccountFolder.exists()) { // if (oldAccountFolder.exists()) {
oldAccountFolder.delete(); // oldAccountFolder.delete();
} // }
} // }
} }
} }
c.close(); c.close();