import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
-import android.os.Environment;
import android.os.RemoteException;
import android.util.Log;
+ e.getMessage());
}
}
+ } else if (fileExists(file.getFileId())) { // for renamed files; no more delete and create
+ OCFile oldFile = getFileById(file.getFileId());
+ if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
+ file.setStoragePath(oldFile.getStoragePath());
+ if (!file.isDirectory());
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+
+ overriden = true;
+ if (getContentResolver() != null) {
+ getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv,
+ ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(file.getFileId()) });
+ } else {
+ try {
+ getContentProvider().update(ProviderTableMeta.CONTENT_URI,
+ cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(file.getFileId()) });
+ } catch (RemoteException e) {
+ Log.e(TAG,
+ "Fail to insert insert file to database "
+ + e.getMessage());
+ }
+ }
} else {
Uri result_uri = null;
if (getContentResolver() != null) {
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
if (fileExists(file.getRemotePath())) {
- OCFile tmpfile = getFileByPath(file.getRemotePath());
- file.setStoragePath(tmpfile.getStoragePath());
+ OCFile oldFile = getFileByPath(file.getRemotePath());
+ if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
+ file.setStoragePath(oldFile.getStoragePath());
if (!file.isDirectory());
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
- file.setFileId(tmpfile.getFileId());
+ file.setFileId(oldFile.getFileId());
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
new String[] { String.valueOf(file.getFileId()) })
.build());
+ } else if (fileExists(file.getFileId())) {
+ OCFile oldFile = getFileById(file.getFileId());
+ if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
+ file.setStoragePath(oldFile.getStoragePath());
+ if (!file.isDirectory());
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+
+ operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
+ withValues(cv).
+ withSelection( ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(file.getFileId()) })
+ .build());
+
} else {
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build());
}
return mContentProvider;
}
+ @Override
public Vector<OCFile> getDirectoryContent(OCFile f) {
if (f != null && f.isDirectory() && f.getFileId() != -1) {
Vector<OCFile> ret = new Vector<OCFile>();
return file;
}
+ @Override
public void removeFile(OCFile file, boolean removeLocalCopy) {
Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
if (getContentProvider() != null) {
if (file.isDown() && removeLocalCopy) {
new File(file.getStoragePath()).delete();
}
+ if (file.isDirectory() && removeLocalCopy) {
+ File f = new File(FileDownloader.getSavePath(mAccount.name) + file.getRemotePath());
+ if (f.exists() && f.isDirectory() && (f.list() == null || f.list().length == 0)) {
+ f.delete();
+ }
+ }
+ }
+
+ @Override
+ public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent) {
+ // TODO consider possible failures
+ if (dir != null && dir.isDirectory() && dir.getFileId() != -1) {
+ Vector<OCFile> children = getDirectoryContent(dir);
+ if (children != null) {
+ OCFile child = null;
+ for (int i=0; i<children.size(); i++) {
+ child = children.get(i);
+ if (child.isDirectory()) {
+ removeDirectory(child, removeDBData, removeLocalContent);
+ } else {
+ if (removeDBData) {
+ removeFile(child, removeLocalContent);
+ } else if (removeLocalContent) {
+ if (child.isDown()) {
+ new File(child.getStoragePath()).delete();
+ }
+ }
+ }
+ }
+ if (removeDBData) {
+ removeFile(dir, true);
+ }
+ }
+ }
}
}