X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/51302a638677b16c5faac6242da44080794f537e..fdb9149e0e0047299bf986006db4a6b0a10f0947:/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 38212785..77575512 100644 --- 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); - 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)); - if (c.moveToFirst()) - return createFileInstance(c); - return null; + OCFile file = null; + if (c.moveToFirst()) { + file = createFileInstance(c); + c.close(); + } + return file; } @Override @@ -92,6 +98,7 @@ public class FileDataStorageManager implements DataStorageManager { cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); if (fileExists(file.getPath())) { + file.setFileId(getFileByPath(file.getPath()).getFileId()); overriden = true; if (getContentResolver() != null) { getContentResolver().update(ProviderTableMeta.CONTENT_URI, @@ -124,7 +131,7 @@ public class FileDataStorageManager implements DataStorageManager { file.setFileId(new_id); } } - + if (file.isDirectory() && file.needsUpdatingWhileSaving()) for (OCFile f : getDirectoryContent(file)) saveFile(f); @@ -157,7 +164,7 @@ public class FileDataStorageManager implements DataStorageManager { } public Vector getDirectoryContent(OCFile f) { - if (f.isDirectory() && f.getFileId() != -1) { + if (f != null && f.isDirectory() && f.getFileId() != -1) { Vector ret = new Vector(); Uri req_uri = Uri.withAppendedPath( @@ -166,13 +173,21 @@ public class FileDataStorageManager implements DataStorageManager { 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 { - 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()) { @@ -194,22 +209,24 @@ public class FileDataStorageManager implements DataStorageManager { 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, - 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; } } - return c.moveToFirst(); + boolean retval = c.moveToFirst(); + c.close(); + return retval; } private Cursor getCursorForValue(String key, String value) { @@ -217,15 +234,15 @@ public class FileDataStorageManager implements DataStorageManager { 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, - 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());