projects
/
pub
/
Android
/
ownCloud.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix crash when deleting used account
[pub/Android/ownCloud.git]
/
src
/
eu
/
alefzero
/
owncloud
/
datamodel
/
FileDataStorageManager.java
diff --git
a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
index
827435f
..
ee874d0
100644
(file)
--- a/
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
+++ b/
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
@@
-53,17
+53,23
@@
public class FileDataStorageManager implements DataStorageManager {
@Override
public OCFile getFileByPath(String path) {
Cursor c = getCursorForValue(ProviderTableMeta.FILE_PATH, path);
@Override
public OCFile getFileByPath(String path) {
Cursor c = getCursorForValue(ProviderTableMeta.FILE_PATH, path);
- if (c.moveToFirst())
- return createFileInstance(c);
- return null;
+ OCFile file = null;
+ if (c.moveToFirst()) {
+ file = createFileInstance(c);
+ c.close();
+ }
+ return file;
}
@Override
public OCFile getFileById(long id) {
Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
}
@Override
public OCFile getFileById(long id) {
Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
- if (c.moveToFirst())
- return createFileInstance(c);
- return null;
+ OCFile file = null;
+ if (c.moveToFirst()) {
+ file = createFileInstance(c);
+ c.close();
+ }
+ return file;
}
@Override
}
@Override
@@
-90,8
+96,13
@@
public class FileDataStorageManager implements DataStorageManager {
cv.put(ProviderTableMeta.FILE_PATH, file.getPath());
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_PATH, file.getPath());
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
-
+
if (fileExists(file.getPath())) {
if (fileExists(file.getPath())) {
+ OCFile tmpfile = getFileByPath(file.getPath());
+ file.setStoragePath(tmpfile.getStoragePath());
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+ file.setFileId(tmpfile.getFileId());
+
overriden = true;
if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI,
overriden = true;
if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI,
@@
-109,17
+120,22
@@
public class FileDataStorageManager implements DataStorageManager {
}
}
} else {
}
}
} else {
+ Uri result_uri = null;
if (getContentResolver() != null) {
if (getContentResolver() != null) {
- getContentResolver().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
+
result_uri =
getContentResolver().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
} else {
try {
} else {
try {
- getContentProvider().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
+
result_uri =
getContentProvider().insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
} catch (RemoteException e) {
Log.e(TAG, "Fail to insert insert file to database " + e.getMessage());
}
}
} catch (RemoteException e) {
Log.e(TAG, "Fail to insert insert file to database " + e.getMessage());
}
}
+ if (result_uri != null) {
+ long new_id = Long.parseLong(result_uri.getPathSegments().get(1));
+ file.setFileId(new_id);
+ }
}
}
-
+
if (file.isDirectory() && file.needsUpdatingWhileSaving())
for (OCFile f : getDirectoryContent(file))
saveFile(f);
if (file.isDirectory() && file.needsUpdatingWhileSaving())
for (OCFile f : getDirectoryContent(file))
saveFile(f);
@@
-152,29
+168,39
@@
public class FileDataStorageManager implements DataStorageManager {
}
public Vector<OCFile> getDirectoryContent(OCFile f) {
}
public Vector<OCFile> getDirectoryContent(OCFile f) {
- if (f.isDirectory() && f.getFileId() != -1) {
+ if (f
!= null && f
.isDirectory() && f.getFileId() != -1) {
Vector<OCFile> ret = new Vector<OCFile>();
Uri req_uri = Uri.withAppendedPath(
ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(f.getFileId()));
Cursor c = null;
Vector<OCFile> ret = new Vector<OCFile>();
Uri req_uri = Uri.withAppendedPath(
ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(f.getFileId()));
Cursor c = null;
+
if (getContentProvider() != null) {
try {
if (getContentProvider() != null) {
try {
- c = getContentProvider().query(req_uri, null, null, null, null);
+ c = getContentProvider().query(req_uri,
+ null,
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+ new String[]{mAccount.name},
+ null);
} catch (RemoteException e) {
Log.e(TAG, e.getMessage());
return ret;
}
} else {
} catch (RemoteException e) {
Log.e(TAG, e.getMessage());
return ret;
}
} else {
- c = getContentResolver().query(req_uri, null, null, null, null);
+ c = getContentResolver().query(req_uri,
+ null,
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+ new String[]{mAccount.name},
+ null);
}
}
- if (c.moveToFirst())
+ if (c.moveToFirst())
{
do {
OCFile child = createFileInstance(c);
ret.add(child);
} while (c.moveToNext());
do {
OCFile child = createFileInstance(c);
ret.add(child);
} while (c.moveToNext());
-
+ }
+
c.close();
return ret;
}
c.close();
return ret;
}
@@
-187,22
+213,24
@@
public class FileDataStorageManager implements DataStorageManager {
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
null,
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
null,
- cmp_key + "=?",
- new String[] {value},
+ cmp_key + "=?
AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?
",
+ new String[] {value
, mAccount.name
},
null);
} else {
try {
c = getContentProvider().query(ProviderTableMeta.CONTENT_URI,
null,
null);
} else {
try {
c = getContentProvider().query(ProviderTableMeta.CONTENT_URI,
null,
- cmp_key + "=?",
- new String[] {value},
+ cmp_key + "=?
AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?
",
+ new String[] {value
, mAccount.name
},
null);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't determine file existance, assuming non existance: " + e.getMessage());
return false;
}
}
null);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't determine file existance, assuming non existance: " + e.getMessage());
return false;
}
}
- return c.moveToFirst();
+ boolean retval = c.moveToFirst();
+ c.close();
+ return retval;
}
private Cursor getCursorForValue(String key, String value) {
}
private Cursor getCursorForValue(String key, String value) {
@@
-210,15
+238,15
@@
public class FileDataStorageManager implements DataStorageManager {
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
null,
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
null,
- key + "=?",
- new String[] {value},
+ key + "=?
AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?
",
+ new String[] {value
, mAccount.name
},
null);
} else {
try {
c = getContentProvider().query(ProviderTableMeta.CONTENT_URI,
null,
null);
} else {
try {
c = getContentProvider().query(ProviderTableMeta.CONTENT_URI,
null,
- key + "=?",
- new String[]{value},
+ key + "=?
AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?
",
+ new String[]{value
, mAccount.name
},
null);
} catch (RemoteException e) {
Log.e(TAG, "Could not get file details: " + e.getMessage());
null);
} catch (RemoteException e) {
Log.e(TAG, "Could not get file details: " + e.getMessage());