import android.net.Uri;
import android.os.RemoteException;
-public class FileDataStorageManager implements DataStorageManager {
+public class FileDataStorageManager {
+
+ public static final int ROOT_PARENT_ID = 0;
private ContentResolver mContentResolver;
- private ContentProviderClient mContentProvider;
+ private ContentProviderClient mContentProviderClient;
private Account mAccount;
- private static String TAG = "FileDataStorageManager";
+ private static String TAG = FileDataStorageManager.class.getSimpleName();
+
public FileDataStorageManager(Account account, ContentResolver cr) {
- mContentProvider = null;
+ mContentProviderClient = null;
mContentResolver = cr;
mAccount = account;
}
public FileDataStorageManager(Account account, ContentProviderClient cp) {
- mContentProvider = cp;
+ mContentProviderClient = cp;
mContentResolver = null;
mAccount = account;
}
- @Override
+
+ public void setAccount(Account account) {
+ mAccount = account;
+ }
+
+ public Account getAccount() {
+ return mAccount;
+ }
+
+ public void setContentResolver(ContentResolver cr) {
+ mContentResolver = cr;
+ }
+
+ public ContentResolver getContentResolver() {
+ return mContentResolver;
+ }
+
+ public void setContentProviderClient(ContentProviderClient cp) {
+ mContentProviderClient = cp;
+ }
+
+ public ContentProviderClient getContentProviderClient() {
+ return mContentProviderClient;
+ }
+
+
public OCFile getFileByPath(String path) {
Cursor c = getCursorForValue(ProviderTableMeta.FILE_PATH, path);
OCFile file = null;
file = createFileInstance(c);
}
c.close();
- if (file == null && OCFile.PATH_SEPARATOR.equals(path)) {
+ if (file == null && OCFile.ROOT_PATH.equals(path)) {
return createRootDir(); // root should always exist
}
return file;
}
- private OCFile createRootDir() {
- OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
- file.setMimetype("DIR");
- file.setParentId(DataStorageManager.ROOT_PARENT_ID);
- saveFile(file);
- return file;
- }
-
- @Override
public OCFile getFileById(long id) {
Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
OCFile file = null;
return file;
}
- @Override
public boolean fileExists(long id) {
return fileExists(ProviderTableMeta._ID, String.valueOf(id));
}
- @Override
public boolean fileExists(String path) {
return fileExists(ProviderTableMeta.FILE_PATH, path);
}
- @Override
+
+ public Vector<OCFile> getFolderContent(OCFile f) {
+ if (f != null && f.isFolder() && f.getFileId() != -1) {
+ return getFolderContent(f.getFileId());
+
+ } else {
+ return new Vector<OCFile>();
+ }
+ }
+
+
+ public Vector<OCFile> getFolderImages(OCFile folder) {
+ Vector<OCFile> ret = new Vector<OCFile>();
+ if (folder != null) {
+ // TODO better implementation, filtering in the access to database (if possible) instead of here
+ Vector<OCFile> tmp = getFolderContent(folder);
+ OCFile current = null;
+ for (int i=0; i<tmp.size(); i++) {
+ current = tmp.get(i);
+ if (current.isImage()) {
+ ret.add(current);
+ }
+ }
+ }
+ return ret;
+ }
+
+
public boolean saveFile(OCFile file) {
boolean overriden = false;
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
- if (file.getParentId() != 0)
+ //if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
- if (!file.isDirectory())
+ if (!file.isFolder())
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
+ cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
boolean sameRemotePath = fileExists(file.getRemotePath());
+ boolean changesSizeOfAncestors = false;
if (sameRemotePath ||
fileExists(file.getFileId()) ) { // for renamed files; no more delete and create
+ OCFile oldFile = null;
if (sameRemotePath) {
- OCFile oldFile = getFileByPath(file.getRemotePath());
+ oldFile = getFileByPath(file.getRemotePath());
file.setFileId(oldFile.getFileId());
+ } else {
+ oldFile = getFileById(file.getFileId());
}
+ changesSizeOfAncestors = (oldFile.getFileLength() != file.getFileLength());
overriden = true;
if (getContentResolver() != null) {
new String[] { String.valueOf(file.getFileId()) });
} else {
try {
- getContentProvider().update(ProviderTableMeta.CONTENT_URI,
+ getContentProviderClient().update(ProviderTableMeta.CONTENT_URI,
cv, ProviderTableMeta._ID + "=?",
new String[] { String.valueOf(file.getFileId()) });
} catch (RemoteException e) {
}
}
} else {
+ changesSizeOfAncestors = true;
Uri result_uri = null;
if (getContentResolver() != null) {
result_uri = getContentResolver().insert(
ProviderTableMeta.CONTENT_URI_FILE, cv);
} else {
try {
- result_uri = getContentProvider().insert(
+ result_uri = getContentProviderClient().insert(
ProviderTableMeta.CONTENT_URI_FILE, cv);
} catch (RemoteException e) {
Log_OC.e(TAG,
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.isFolder()) {
+ calculateFolderSize(file.getFileId());
+ if (file.needsUpdatingWhileSaving()) {
+ for (OCFile f : getFolderContent(file))
+ saveFile(f);
+ }
+ }
+
+ if (changesSizeOfAncestors || file.isFolder()) {
+ updateSizesToTheRoot(file.getParentId());
+ }
+
return overriden;
}
- @Override
public void saveFiles(List<OCFile> files) {
Iterator<OCFile> filesIt = files.iterator();
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
- if (file.getParentId() != 0)
+ if (file.getParentId() != FileDataStorageManager.ROOT_PARENT_ID)
cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
- if (!file.isDirectory())
+ if (!file.isFolder())
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
+ cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
if (fileExists(file.getRemotePath())) {
OCFile oldFile = getFileByPath(file.getRemotePath());
file.setFileId(oldFile.getFileId());
+
+ if (file.isFolder()) {
+ cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
+ file.setFileLength(oldFile.getFileLength());
+ }
+
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
withSelection( ProviderTableMeta._ID + "=?",
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());
-
+
+ if (!file.isFolder())
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+ else {
+ cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
+ file.setFileLength(oldFile.getFileLength());
+ }
+
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
withSelection( ProviderTableMeta._ID + "=?",
results = getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations);
} else {
- results = getContentProvider().applyBatch(operations);
+ results = getContentProviderClient().applyBatch(operations);
}
} catch (OperationApplicationException e) {
}
for (OCFile aFile : files) {
- if (aFile.isDirectory() && aFile.needsUpdatingWhileSaving())
- saveFiles(getDirectoryContent(aFile));
- }
-
- }
-
- public void setAccount(Account account) {
- mAccount = account;
- }
-
- public Account getAccount() {
- return mAccount;
- }
-
- public void setContentResolver(ContentResolver cr) {
- mContentResolver = cr;
- }
-
- public ContentResolver getContentResolver() {
- return mContentResolver;
- }
-
- public void setContentProvider(ContentProviderClient cp) {
- mContentProvider = cp;
- }
-
- public ContentProviderClient getContentProvider() {
- return mContentProvider;
- }
-
- @Override
- public Vector<OCFile> getDirectoryContent(OCFile f) {
- Vector<OCFile> ret = new Vector<OCFile>();
- if (f != null && f.isDirectory() && f.getFileId() != -1) {
-
- Uri req_uri = Uri.withAppendedPath(
- ProviderTableMeta.CONTENT_URI_DIR,
- String.valueOf(f.getFileId()));
- Cursor c = null;
-
- if (getContentProvider() != null) {
- try {
- c = getContentProvider().query(req_uri, null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
- new String[] { mAccount.name }, null);
- } catch (RemoteException e) {
- Log_OC.e(TAG, e.getMessage());
- return ret;
- }
- } else {
- c = getContentResolver().query(req_uri, null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
- new String[] { mAccount.name }, null);
- }
-
- if (c.moveToFirst()) {
- do {
- OCFile child = createFileInstance(c);
- ret.add(child);
- } while (c.moveToNext());
- }
-
- c.close();
-
- Collections.sort(ret);
-
+ if (aFile.isFolder() && aFile.needsUpdatingWhileSaving())
+ saveFiles(getFolderContent(aFile));
}
- return ret;
- }
- private boolean fileExists(String cmp_key, String value) {
- Cursor c;
- if (getContentResolver() != null) {
- c = getContentResolver()
- .query(ProviderTableMeta.CONTENT_URI,
- null,
- cmp_key + "=? AND "
- + ProviderTableMeta.FILE_ACCOUNT_OWNER
- + "=?",
- new String[] { value, mAccount.name }, null);
- } else {
- try {
- c = getContentProvider().query(
- ProviderTableMeta.CONTENT_URI,
- null,
- cmp_key + "=? AND "
- + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
- new String[] { value, mAccount.name }, null);
- } catch (RemoteException e) {
- Log_OC.e(TAG,
- "Couldn't determine file existance, assuming non existance: "
- + e.getMessage());
- return false;
- }
- }
- boolean retval = c.moveToFirst();
- c.close();
- return retval;
}
- private Cursor getCursorForValue(String key, String value) {
- Cursor c = null;
- if (getContentResolver() != null) {
- c = getContentResolver()
- .query(ProviderTableMeta.CONTENT_URI,
- null,
- key + "=? AND "
- + ProviderTableMeta.FILE_ACCOUNT_OWNER
- + "=?",
- new String[] { value, mAccount.name }, null);
- } else {
- try {
- c = getContentProvider().query(
- ProviderTableMeta.CONTENT_URI,
- null,
- key + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER
- + "=?", new String[] { value, mAccount.name },
- null);
- } catch (RemoteException e) {
- Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
- c = null;
- }
- }
- return c;
- }
- private OCFile createFileInstance(Cursor c) {
- OCFile file = null;
- if (c != null) {
- file = new OCFile(c.getString(c
- .getColumnIndex(ProviderTableMeta.FILE_PATH)));
- file.setFileId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
- file.setParentId(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_PARENT)));
- file.setMimetype(c.getString(c
- .getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
- if (!file.isDirectory()) {
- file.setStoragePath(c.getString(c
- .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
- if (file.getStoragePath() == null) {
- // try to find existing file and bind it with current account; - with the current update of SynchronizeFolderOperation, this won't be necessary anymore after a full synchronization of the account
- File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
- if (f.exists()) {
- file.setStoragePath(f.getAbsolutePath());
- file.setLastSyncDateForData(f.lastModified());
- }
- }
- }
- file.setFileLength(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)));
- file.setCreationTimestamp(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_CREATION)));
- file.setModificationTimestamp(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
- file.setModificationTimestampAtLastSyncForData(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
- file.setLastSyncDateForProperties(c.getLong(c
- .getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
- file.setLastSyncDateForData(c.getLong(c.
- getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
- file.setKeepInSync(c.getInt(
- c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
+ /**
+ * Calculate and save the folderSize on DB
+ * @param id
+ */
+ public void calculateFolderSize(long id) {
+ long folderSize = 0;
+
+ Vector<OCFile> files = getFolderContent(id);
+
+ for (OCFile f: files)
+ {
+ folderSize = folderSize + f.getFileLength();
}
- return file;
+
+ updateSize(id, folderSize);
}
-
- @Override
+
+
public void removeFile(OCFile file, boolean removeLocalCopy) {
Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
- if (getContentProvider() != null) {
+ if (getContentProviderClient() != null) {
try {
- getContentProvider().delete(file_uri,
+ getContentProviderClient().delete(file_uri,
ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
new String[]{mAccount.name});
} catch (RemoteException e) {
if (file.isDown() && removeLocalCopy) {
new File(file.getStoragePath()).delete();
}
- if (file.isDirectory() && removeLocalCopy) {
+ if (file.isFolder() && removeLocalCopy) {
File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
if (f.exists() && f.isDirectory() && (f.list() == null || f.list().length == 0)) {
f.delete();
}
}
+
+ if (file.getFileLength() > 0) {
+ updateSizesToTheRoot(file.getParentId());
+ }
}
- @Override
- public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent) {
+ public void removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
// TODO consider possible failures
- if (dir != null && dir.isDirectory() && dir.getFileId() != -1) {
- Vector<OCFile> children = getDirectoryContent(dir);
+ if (folder != null && folder.isFolder() && folder.getFileId() != -1) {
+ Vector<OCFile> children = getFolderContent(folder);
if (children.size() > 0) {
OCFile child = null;
for (int i=0; i<children.size(); i++) {
child = children.get(i);
- if (child.isDirectory()) {
- removeDirectory(child, removeDBData, removeLocalContent);
+ if (child.isFolder()) {
+ removeFolder(child, removeDBData, removeLocalContent);
} else {
if (removeDBData) {
removeFile(child, removeLocalContent);
}
}
if (removeDBData) {
- removeFile(dir, true);
+ removeFile(folder, true);
+ }
+
+ if (folder.getFileLength() > 0) {
+ updateSizesToTheRoot(folder.getParentId());
}
}
}
* TODO explore better (faster) implementations
* TODO throw exceptions up !
*/
- @Override
- public void moveDirectory(OCFile dir, String newPath) {
+ public void moveFolder(OCFile folder, String newPath) {
// TODO check newPath
- if (dir != null && dir.isDirectory() && dir.fileExists() && !dir.getFileName().equals(OCFile.PATH_SEPARATOR)) {
+ if (folder != null && folder.isFolder() && folder.fileExists() && !OCFile.ROOT_PATH.equals(folder.getFileName())) {
/// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
Cursor c = null;
- if (getContentProvider() != null) {
+ if (getContentProviderClient() != null) {
try {
- c = getContentProvider().query(ProviderTableMeta.CONTENT_URI,
+ c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI,
null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ?",
- new String[] { mAccount.name, dir.getRemotePath() + "%" }, null);
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+ new String[] { mAccount.name, folder.getRemotePath() + "%" }, ProviderTableMeta.FILE_PATH + " ASC ");
} catch (RemoteException e) {
Log_OC.e(TAG, e.getMessage());
}
} else {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ?",
- new String[] { mAccount.name, dir.getRemotePath() + "%" }, null);
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+ new String[] { mAccount.name, folder.getRemotePath() + "%" }, ProviderTableMeta.FILE_PATH + " ASC ");
}
/// 2. prepare a batch of update operations to change all the descendants
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(c.getCount());
- int lengthOfOldPath = dir.getRemotePath().length();
+ int lengthOfOldPath = folder.getRemotePath().length();
String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
if (c.moveToFirst()) {
getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations);
} else {
- getContentProvider().applyBatch(operations);
+ getContentProviderClient().applyBatch(operations);
}
} catch (OperationApplicationException e) {
- Log_OC.e(TAG, "Fail to update descendants of " + dir.getFileId() + " in database", e);
+ Log_OC.e(TAG, "Fail to update descendants of " + folder.getFileId() + " in database", e);
} catch (RemoteException e) {
- Log_OC.e(TAG, "Fail to update desendants of " + dir.getFileId() + " in database", e);
+ Log_OC.e(TAG, "Fail to update desendants of " + folder.getFileId() + " in database", e);
}
}
}
- @Override
- public Vector<OCFile> getDirectoryImages(OCFile directory) {
- Vector<OCFile> ret = new Vector<OCFile>();
- if (directory != null) {
- // TODO better implementation, filtering in the access to database (if possible) instead of here
- Vector<OCFile> tmp = getDirectoryContent(directory);
- OCFile current = null;
- for (int i=0; i<tmp.size(); i++) {
- current = tmp.get(i);
- if (current.isImage()) {
- ret.add(current);
- }
- }
- }
- return ret;
- }
-
- @Override
- public Vector<OCFile> getFilesbyParent(long parentId) {
+
+ private Vector<OCFile> getFolderContent(long parentId) {
Vector<OCFile> ret = new Vector<OCFile>();
String.valueOf(parentId));
Cursor c = null;
- if (getContentProvider() != null) {
+ if (getContentProviderClient() != null) {
try {
- c = getContentProvider().query(req_uri, null,
+ c = getContentProviderClient().query(req_uri, null,
ProviderTableMeta.FILE_PARENT + "=?" ,
new String[] { String.valueOf(parentId)}, null);
} catch (RemoteException e) {
return ret;
}
+
+
+ private OCFile createRootDir() {
+ OCFile file = new OCFile(OCFile.ROOT_PATH);
+ file.setMimetype("DIR");
+ file.setParentId(FileDataStorageManager.ROOT_PARENT_ID);
+ saveFile(file);
+ return file;
+ }
+
+ private boolean fileExists(String cmp_key, String value) {
+ Cursor c;
+ if (getContentResolver() != null) {
+ c = getContentResolver()
+ .query(ProviderTableMeta.CONTENT_URI,
+ null,
+ cmp_key + "=? AND "
+ + ProviderTableMeta.FILE_ACCOUNT_OWNER
+ + "=?",
+ new String[] { value, mAccount.name }, null);
+ } else {
+ try {
+ c = getContentProviderClient().query(
+ ProviderTableMeta.CONTENT_URI,
+ null,
+ cmp_key + "=? AND "
+ + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
+ new String[] { value, mAccount.name }, null);
+ } catch (RemoteException e) {
+ Log_OC.e(TAG,
+ "Couldn't determine file existance, assuming non existance: "
+ + e.getMessage());
+ return false;
+ }
+ }
+ boolean retval = c.moveToFirst();
+ c.close();
+ return retval;
+ }
+
+ private Cursor getCursorForValue(String key, String value) {
+ Cursor c = null;
+ if (getContentResolver() != null) {
+ c = getContentResolver()
+ .query(ProviderTableMeta.CONTENT_URI,
+ null,
+ key + "=? AND "
+ + ProviderTableMeta.FILE_ACCOUNT_OWNER
+ + "=?",
+ new String[] { value, mAccount.name }, null);
+ } else {
+ try {
+ c = getContentProviderClient().query(
+ ProviderTableMeta.CONTENT_URI,
+ null,
+ key + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER
+ + "=?", new String[] { value, mAccount.name },
+ null);
+ } catch (RemoteException e) {
+ Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
+ c = null;
+ }
+ }
+ return c;
+ }
+
+ private OCFile createFileInstance(Cursor c) {
+ OCFile file = null;
+ if (c != null) {
+ file = new OCFile(c.getString(c
+ .getColumnIndex(ProviderTableMeta.FILE_PATH)));
+ file.setFileId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
+ file.setParentId(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_PARENT)));
+ file.setMimetype(c.getString(c
+ .getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
+ if (!file.isFolder()) {
+ file.setStoragePath(c.getString(c
+ .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
+ if (file.getStoragePath() == null) {
+ // try to find existing file and bind it with current account; - with the current update of SynchronizeFolderOperation, this won't be necessary anymore after a full synchronization of the account
+ File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
+ if (f.exists()) {
+ file.setStoragePath(f.getAbsolutePath());
+ file.setLastSyncDateForData(f.lastModified());
+ }
+ }
+ }
+ file.setFileLength(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)));
+ file.setCreationTimestamp(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_CREATION)));
+ file.setModificationTimestamp(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
+ file.setModificationTimestampAtLastSyncForData(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
+ file.setLastSyncDateForProperties(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
+ file.setLastSyncDateForData(c.getLong(c.
+ getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
+ file.setKeepInSync(c.getInt(
+ c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
+ file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG)));
+
+ }
+ return file;
+ }
/**
- * Update the size value of a folder
+ * Update the size value of an OCFile in DB
*/
- @Override
- public int updatefolderSize(long id, long size)
- {
+ private int updateSize(long id, long size) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, size);
- int result = getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?",
- new String[] { String.valueOf(id) });
+ int result = -1;
+ if (getContentResolver() != null) {
+ result = getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(id) });
+ } else {
+ try {
+ result = getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(id) });
+ } catch (RemoteException e) {
+ Log_OC.e(TAG,"Fail to update size column into database " + e.getMessage());
+ }
+ }
return result;
}
+ /**
+ * Update the size of a subtree of folder from a file to the root
+ * @param parentId: parent of the file
+ */
+ private void updateSizesToTheRoot(long parentId) {
+
+ OCFile file;
+
+ while (parentId != FileDataStorageManager.ROOT_PARENT_ID) {
+
+ // Update the size of the parent
+ calculateFolderSize(parentId);
+
+ // search the next parent
+ file = getFileById(parentId);
+ parentId = file.getParentId();
+
+ }
+
+ }
}