From: David A. Velasco Date: Tue, 20 May 2014 08:30:02 +0000 (+0200) Subject: Fixed local removal of files when a folder is removed locally and holds local files... X-Git-Tag: oc-android-1.7.0_signed~309^2~8^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1664299bd2ab1800b7d66db966295dd0d9a24a09?hp=--cc Fixed local removal of files when a folder is removed locally and holds local files currently out of sync --- 1664299bd2ab1800b7d66db966295dd0d9a24a09 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index ec0a7efc..efbb9222 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1,6 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-2014 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -494,6 +494,7 @@ public class FileDataStorageManager { boolean success = true; File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder)); if (localFolder.exists()) { + // stage 1: remove the local files already registered in the files database Vector files = getFolderContent(folder.getFileId()); if (files != null) { for (OCFile file : files) { @@ -511,8 +512,27 @@ public class FileDataStorageManager { } } } - success &= localFolder.delete(); + + // stage 2: remove the folder itself and any local file inside out of sync; + // for instance, after clearing the app cache or reinstalling + success &= removeLocalFolder(localFolder); + } + return success; + } + + private boolean removeLocalFolder(File localFolder) { + boolean success = true; + File[] localFiles = localFolder.listFiles(); + if (localFiles != null) { + for (File localFile : localFiles) { + if (localFile.isDirectory()) { + success &= removeLocalFolder(localFile); + } else { + success &= localFile.delete(); + } + } } + success &= localFolder.delete(); return success; }