From 938c78466b89ee30d439462ded5b4b25c79190ce Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Wed, 22 Aug 2012 12:50:06 +0200 Subject: [PATCH] Local files are protected against removal because of synchronization when out of the owncloud folder --- src/com/owncloud/android/datamodel/DataStorageManager.java | 2 +- .../owncloud/android/datamodel/FileDataStorageManager.java | 4 ++-- src/com/owncloud/android/syncadapter/FileSyncAdapter.java | 3 ++- src/com/owncloud/android/ui/fragment/FileDetailFragment.java | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/com/owncloud/android/datamodel/DataStorageManager.java b/src/com/owncloud/android/datamodel/DataStorageManager.java index a73ab66cea..e824bdea77 100644 --- a/src/com/owncloud/android/datamodel/DataStorageManager.java +++ b/src/com/owncloud/android/datamodel/DataStorageManager.java @@ -37,5 +37,5 @@ public interface DataStorageManager { public Vector getDirectoryContent(OCFile f); - public void removeFile(OCFile file); + public void removeFile(OCFile file, boolean removeLocalCopy); } diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 49a88c3667..7bb29d469e 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -399,7 +399,7 @@ public class FileDataStorageManager implements DataStorageManager { return file; } - public void removeFile(OCFile file) { + public void removeFile(OCFile file, boolean removeLocalCopy) { Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId()); if (getContentProvider() != null) { try { @@ -414,7 +414,7 @@ public class FileDataStorageManager implements DataStorageManager { ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", new String[]{mAccount.name}); } - if (file.isDown()) { + if (file.isDown() && removeLocalCopy) { new File(file.getStoragePath()).delete(); } } diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 1a3afe61a6..7b803fc178 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -210,11 +210,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { Vector files = getStorageManager().getDirectoryContent( getStorageManager().getFileById(parentId)); OCFile file; + String currentSavePath = FileDownloader.getSavePath(mAccount.name); for (int i=0; i < files.size(); ) { file = files.get(i); if (file.getLastSyncDate() != mCurrentSyncTime) { Log.v(TAG, "removing file: " + file); - getStorageManager().removeFile(file); + getStorageManager().removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); files.remove(i); } else { i++; diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index a77d9ad660..979930d171 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -842,7 +842,7 @@ public class FileDetailFragment extends SherlockFragment implements if (success) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mOld); + fdsm.removeFile(mOld, false); fdsm.saveFile(mNew); mFile = mNew; mHandler.post(new Runnable() { @@ -1008,7 +1008,7 @@ public class FileDetailFragment extends SherlockFragment implements if (success) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mFileToRemove); + fdsm.removeFile(mFileToRemove, true); mHandler.post(new Runnable() { @Override public void run() {