private void removeObsoleteFiles() {
mChildren = mStorageManager.getDirectoryContent(mLocalFolder);
OCFile file;
- String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
for (int i=0; i < mChildren.size(); ) {
file = mChildren.get(i);
if (file.getLastSyncDateForProperties() != mCurrentSyncTime) {
- Log_OC.d(TAG, "removing file: " + file);
- mStorageManager.removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath)));
+ if (file.isDirectory()) {
+ Log_OC.d(TAG, "removing folder: " + file);
+ mStorageManager.removeDirectory(file, true, true);
+ } else {
+ Log_OC.d(TAG, "removing file: " + file);
+ mStorageManager.removeFile(file, true);
+ }
mChildren.remove(i);
} else {
i++;
finish();
return;
}
- popDirname();
- listOfFiles.onBrowseUp();
+ int levelsUp = listOfFiles.onBrowseUp();
+ for (int i=0; i < levelsUp && mDirectories.getCount() > 1 ; i++) {
+ popDirname();
+ }
}
}
if (listOfFiles != null) { // should never be null, indeed
String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
- OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileById(getFile().getFileId());
- OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileById(getCurrentDir().getFileId());
+ OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath());
+ OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath());
if (currentDir == null) {
// current folder was removed from the server
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileHandler;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
+import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.TransferServiceGetter;
import com.owncloud.android.ui.adapter.FileListListAdapter;
/**
- * Call this, when the user presses the up button
+ * Call this, when the user presses the up button.
+ *
+ * Tries to move up the current folder one level. If the parent folder was removed from the database,
+ * it continues browsing up until finding an existing folders.
+ *
+ * return Count of folder levels browsed up.
*/
- public void onBrowseUp() {
+ public int onBrowseUp() {
OCFile parentDir = null;
+ int moveCount = 0;
if(mFile != null){
DataStorageManager storageManager = mContainerActivity.getStorageManager();
- if (mFile.getParentId() == 0) {
- parentDir = storageManager.getFileById(1);
- }
- else {
- parentDir = storageManager.getFileById(mFile.getParentId());
- }
+ String parentPath = null;
+ if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
+ parentPath = new File(mFile.getRemotePath()).getParent();
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
+ parentDir = storageManager.getFileByPath(parentPath);
+ moveCount++;
+ } else {
+ parentDir = storageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null; keep the path in root folder
+ }
+ while (parentDir == null) {
+ parentPath = new File(parentPath).getParent();
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
+ parentDir = storageManager.getFileByPath(parentPath);
+ moveCount++;
+ } // exit is granted because storageManager.getFileByPath("/") never returns null
mFile = parentDir;
}
listDirectory(mFile);
mContainerActivity.startSyncFolderOperation(mFile);
- }
+ } // else - should never happen now
+ return moveCount;
}
@Override