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

@ -374,9 +374,9 @@ public class FileContentProvider extends ContentProvider {
) { ) {
ContentValues fileValues = new ContentValues(); ContentValues fileValues = new ContentValues();
fileValues.put( fileValues.put(
ProviderTableMeta.FILE_SHARE_BY_LINK, ProviderTableMeta.FILE_SHARE_BY_LINK,
ShareType.PUBLIC_LINK.getValue() == ShareType.PUBLIC_LINK.getValue() ==
shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE)? 1 : 0 shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE) ? 1 : 0
); );
String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " + String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " +
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
@ -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 " +
@ -896,18 +895,19 @@ public class FileContentProvider extends ContentProvider {
ProviderTableMeta.FILE_ACCOUNT_OWNER +"=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER +"=? AND " +
ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL;"; ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL;";
Cursor c = db.rawQuery(selectQuery, new String[] { newAccountName }); Cursor c = db.rawQuery(selectQuery, new String[]{newAccountName});
if (c.moveToFirst()) { if (c.moveToFirst()) {
// create storage path // create storage path
String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName); String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
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();