1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.datamodel
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Collection
;
24 import java
.util
.Collections
;
25 import java
.util
.Iterator
;
26 import java
.util
.Vector
;
28 import com
.owncloud
.android
.Log_OC
;
29 import com
.owncloud
.android
.MainApp
;
30 import com
.owncloud
.android
.db
.ProviderMeta
.ProviderTableMeta
;
31 import com
.owncloud
.android
.utils
.FileStorageUtils
;
33 import android
.accounts
.Account
;
34 import android
.content
.ContentProviderClient
;
35 import android
.content
.ContentProviderOperation
;
36 import android
.content
.ContentProviderResult
;
37 import android
.content
.ContentResolver
;
38 import android
.content
.ContentUris
;
39 import android
.content
.ContentValues
;
40 import android
.content
.OperationApplicationException
;
41 import android
.database
.Cursor
;
42 import android
.net
.Uri
;
43 import android
.os
.RemoteException
;
45 public class FileDataStorageManager
{
47 public static final int ROOT_PARENT_ID
= 0;
49 private ContentResolver mContentResolver
;
50 private ContentProviderClient mContentProviderClient
;
51 private Account mAccount
;
53 private static String TAG
= FileDataStorageManager
.class.getSimpleName();
56 public FileDataStorageManager(Account account
, ContentResolver cr
) {
57 mContentProviderClient
= null
;
58 mContentResolver
= cr
;
62 public FileDataStorageManager(Account account
, ContentProviderClient cp
) {
63 mContentProviderClient
= cp
;
64 mContentResolver
= null
;
69 public void setAccount(Account account
) {
73 public Account
getAccount() {
77 public void setContentResolver(ContentResolver cr
) {
78 mContentResolver
= cr
;
81 public ContentResolver
getContentResolver() {
82 return mContentResolver
;
85 public void setContentProviderClient(ContentProviderClient cp
) {
86 mContentProviderClient
= cp
;
89 public ContentProviderClient
getContentProviderClient() {
90 return mContentProviderClient
;
94 public OCFile
getFileByPath(String path
) {
95 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_PATH
, path
);
97 if (c
.moveToFirst()) {
98 file
= createFileInstance(c
);
101 if (file
== null
&& OCFile
.ROOT_PATH
.equals(path
)) {
102 return createRootDir(); // root should always exist
108 public OCFile
getFileById(long id
) {
109 Cursor c
= getCursorForValue(ProviderTableMeta
._ID
, String
.valueOf(id
));
111 if (c
.moveToFirst()) {
112 file
= createFileInstance(c
);
118 public OCFile
getFileByLocalPath(String path
) {
119 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_STORAGE_PATH
, path
);
121 if (c
.moveToFirst()) {
122 file
= createFileInstance(c
);
128 public boolean fileExists(long id
) {
129 return fileExists(ProviderTableMeta
._ID
, String
.valueOf(id
));
132 public boolean fileExists(String path
) {
133 return fileExists(ProviderTableMeta
.FILE_PATH
, path
);
137 public Vector
<OCFile
> getFolderContent(OCFile f
) {
138 if (f
!= null
&& f
.isFolder() && f
.getFileId() != -1) {
139 return getFolderContent(f
.getFileId());
142 return new Vector
<OCFile
>();
147 public Vector
<OCFile
> getFolderImages(OCFile folder
) {
148 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
149 if (folder
!= null
) {
150 // TODO better implementation, filtering in the access to database (if possible) instead of here
151 Vector
<OCFile
> tmp
= getFolderContent(folder
);
152 OCFile current
= null
;
153 for (int i
=0; i
<tmp
.size(); i
++) {
154 current
= tmp
.get(i
);
155 if (current
.isImage()) {
164 public boolean saveFile(OCFile file
) {
165 boolean overriden
= false
;
166 ContentValues cv
= new ContentValues();
167 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
168 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
169 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
170 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
171 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
172 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
173 //if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
174 cv
.put(ProviderTableMeta
.FILE_PARENT
, file
.getParentId());
175 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
176 if (!file
.isFolder())
177 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
178 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
179 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
180 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
181 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
182 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
184 boolean sameRemotePath
= fileExists(file
.getRemotePath());
185 if (sameRemotePath
||
186 fileExists(file
.getFileId()) ) { // for renamed files; no more delete and create
188 OCFile oldFile
= null
;
189 if (sameRemotePath
) {
190 oldFile
= getFileByPath(file
.getRemotePath());
191 file
.setFileId(oldFile
.getFileId());
193 oldFile
= getFileById(file
.getFileId());
197 if (getContentResolver() != null
) {
198 getContentResolver().update(ProviderTableMeta
.CONTENT_URI
, cv
,
199 ProviderTableMeta
._ID
+ "=?",
200 new String
[] { String
.valueOf(file
.getFileId()) });
203 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI
,
204 cv
, ProviderTableMeta
._ID
+ "=?",
205 new String
[] { String
.valueOf(file
.getFileId()) });
206 } catch (RemoteException e
) {
208 "Fail to insert insert file to database "
213 Uri result_uri
= null
;
214 if (getContentResolver() != null
) {
215 result_uri
= getContentResolver().insert(
216 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
219 result_uri
= getContentProviderClient().insert(
220 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
221 } catch (RemoteException e
) {
223 "Fail to insert insert file to database "
227 if (result_uri
!= null
) {
228 long new_id
= Long
.parseLong(result_uri
.getPathSegments()
230 file
.setFileId(new_id
);
234 if (file
.isFolder()) {
235 updateFolderSize(file
.getFileId());
237 updateFolderSize(file
.getParentId());
245 * Inserts or updates the list of files contained in a given folder.
247 * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD.
248 * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED
252 * @param removeNotUpdated
254 public void saveFolder(OCFile folder
, Collection
<OCFile
> updatedFiles
, Collection
<OCFile
> filesToRemove
) {
256 Log_OC
.d(TAG
, "Saving folder " + folder
.getRemotePath() + " with " + updatedFiles
.size() + " children and " + filesToRemove
.size() + " files to remove");
258 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(updatedFiles
.size());
260 // prepare operations to insert or update files to save in the given folder
261 for (OCFile file
: updatedFiles
) {
262 ContentValues cv
= new ContentValues();
263 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
264 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
265 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
266 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
267 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
268 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
269 //cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
270 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getFileId());
271 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
272 if (!file
.isFolder()) {
273 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
275 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
276 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
277 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
278 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
279 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
281 boolean existsByPath
= fileExists(file
.getRemotePath());
282 if (existsByPath
|| fileExists(file
.getFileId())) {
283 // updating an existing file
284 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
286 withSelection( ProviderTableMeta
._ID
+ "=?",
287 new String
[] { String
.valueOf(file
.getFileId()) })
292 operations
.add(ContentProviderOperation
.newInsert(ProviderTableMeta
.CONTENT_URI
).withValues(cv
).build());
296 // prepare operations to remove files in the given folder
297 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
298 String
[] whereArgs
= null
;
299 for (OCFile file
: filesToRemove
) {
300 if (file
.getParentId() == folder
.getFileId()) {
301 whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
302 //Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, "" + file.getFileId());
303 if (file
.isFolder()) {
304 operations
.add(ContentProviderOperation
305 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_DIR
, file
.getFileId())).withSelection(where
, whereArgs
)
307 // TODO remove local folder
309 operations
.add(ContentProviderOperation
310 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId())).withSelection(where
, whereArgs
)
313 new File(file
.getStoragePath()).delete();
314 // TODO move the deletion of local contents after success of deletions
320 // update metadata of folder
321 ContentValues cv
= new ContentValues();
322 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, folder
.getModificationTimestamp());
323 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, folder
.getModificationTimestampAtLastSyncForData());
324 cv
.put(ProviderTableMeta
.FILE_CREATION
, folder
.getCreationTimestamp());
325 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, 0); // FileContentProvider calculates the right size
326 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, folder
.getMimetype());
327 cv
.put(ProviderTableMeta
.FILE_NAME
, folder
.getFileName());
328 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getParentId());
329 cv
.put(ProviderTableMeta
.FILE_PATH
, folder
.getRemotePath());
330 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
331 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, folder
.getLastSyncDateForProperties());
332 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, folder
.getLastSyncDateForData());
333 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, folder
.keepInSync() ?
1 : 0);
334 cv
.put(ProviderTableMeta
.FILE_ETAG
, folder
.getEtag());
335 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
337 withSelection( ProviderTableMeta
._ID
+ "=?",
338 new String
[] { String
.valueOf(folder
.getFileId()) })
341 // apply operations in batch
342 ContentProviderResult
[] results
= null
;
343 Log_OC
.d(TAG
, "Sending " + operations
.size() + " operations to FileContentProvider");
345 if (getContentResolver() != null
) {
346 results
= getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
349 results
= getContentProviderClient().applyBatch(operations
);
352 } catch (OperationApplicationException e
) {
353 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
355 } catch (RemoteException e
) {
356 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
359 // update new id in file objects for insertions
360 if (results
!= null
) {
362 Iterator
<OCFile
> filesIt
= updatedFiles
.iterator();
364 for (int i
=0; i
<results
.length
; i
++) {
365 if (filesIt
.hasNext()) {
366 file
= filesIt
.next();
370 if (results
[i
].uri
!= null
) {
371 newId
= Long
.parseLong(results
[i
].uri
.getPathSegments().get(1));
372 //updatedFiles.get(i).setFileId(newId);
374 file
.setFileId(newId
);
380 updateFolderSize(folder
.getFileId());
389 private void updateFolderSize(long id
) {
390 if (id
> FileDataStorageManager
.ROOT_PARENT_ID
) {
391 Log_OC
.d(TAG
, "Updating size of " + id
);
392 if (getContentResolver() != null
) {
393 getContentResolver().update(ProviderTableMeta
.CONTENT_URI_DIR
, null
,
394 ProviderTableMeta
._ID
+ "=?",
395 new String
[] { String
.valueOf(id
) });
398 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI_DIR
, null
,
399 ProviderTableMeta
._ID
+ "=?",
400 new String
[] { String
.valueOf(id
) });
402 } catch (RemoteException e
) {
403 Log_OC
.e(TAG
, "Exception in update of folder size through compatibility patch " + e
.getMessage());
407 Log_OC
.e(TAG
, "not updating size for folder " + id
);
412 public void removeFile(OCFile file
, boolean removeDBData
, boolean removeLocalCopy
) {
414 if (file
.isFolder()) {
415 removeFolder(file
, removeDBData
, removeLocalCopy
);
419 //Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
420 Uri file_uri
= ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId());
421 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
422 String
[] whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
423 if (getContentProviderClient() != null
) {
425 getContentProviderClient().delete(file_uri
, where
, whereArgs
);
426 } catch (RemoteException e
) {
430 getContentResolver().delete(file_uri
, where
, whereArgs
);
432 updateFolderSize(file
.getParentId());
434 if (removeLocalCopy
&& file
.isDown()) {
435 boolean success
= new File(file
.getStoragePath()).delete();
436 if (!removeDBData
&& success
) {
437 // maybe unnecessary, but should be checked TODO remove if unnecessary
438 file
.setStoragePath(null
);
447 public void removeFolder(OCFile folder
, boolean removeDBData
, boolean removeLocalContent
) {
448 if (folder
!= null
&& folder
.isFolder()) {
449 if (removeDBData
&& folder
.getFileId() != -1) {
450 removeFolderInDb(folder
);
452 if (removeLocalContent
) {
453 File localFolder
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, folder
));
454 removeLocalFolder(localFolder
);
459 private void removeFolderInDb(OCFile folder
) {
460 Uri folder_uri
= Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, ""+ folder
.getFileId()); // URI for recursive deletion
461 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
462 String
[] whereArgs
= new String
[]{mAccount
.name
, folder
.getRemotePath()};
463 if (getContentProviderClient() != null
) {
465 getContentProviderClient().delete(folder_uri
, where
, whereArgs
);
466 } catch (RemoteException e
) {
470 getContentResolver().delete(folder_uri
, where
, whereArgs
);
472 updateFolderSize(folder
.getParentId());
475 private void removeLocalFolder(File folder
) {
476 if (folder
.exists()) {
477 File
[] files
= folder
.listFiles();
479 for (File file
: files
) {
480 if (file
.isDirectory()) {
481 removeLocalFolder(file
);
492 * Updates database for a folder that was moved to a different location.
494 * TODO explore better (faster) implementations
495 * TODO throw exceptions up !
497 public void moveFolder(OCFile folder
, String newPath
) {
498 // TODO check newPath
500 if (folder
!= null
&& folder
.isFolder() && folder
.fileExists() && !OCFile
.ROOT_PATH
.equals(folder
.getFileName())) {
501 /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
503 if (getContentProviderClient() != null
) {
505 c
= getContentProviderClient().query(ProviderTableMeta
.CONTENT_URI
,
507 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
508 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
509 } catch (RemoteException e
) {
510 Log_OC
.e(TAG
, e
.getMessage());
513 c
= getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
515 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
516 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
519 /// 2. prepare a batch of update operations to change all the descendants
520 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(c
.getCount());
521 int lengthOfOldPath
= folder
.getRemotePath().length();
522 String defaultSavePath
= FileStorageUtils
.getSavePath(mAccount
.name
);
523 int lengthOfOldStoragePath
= defaultSavePath
.length() + lengthOfOldPath
;
524 if (c
.moveToFirst()) {
526 ContentValues cv
= new ContentValues(); // don't take the constructor out of the loop and clear the object
527 OCFile child
= createFileInstance(c
);
528 cv
.put(ProviderTableMeta
.FILE_PATH
, newPath
+ child
.getRemotePath().substring(lengthOfOldPath
));
529 if (child
.getStoragePath() != null
&& child
.getStoragePath().startsWith(defaultSavePath
)) {
530 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, defaultSavePath
+ newPath
+ child
.getStoragePath().substring(lengthOfOldStoragePath
));
532 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
534 withSelection( ProviderTableMeta
._ID
+ "=?",
535 new String
[] { String
.valueOf(child
.getFileId()) })
537 } while (c
.moveToNext());
541 /// 3. apply updates in batch
543 if (getContentResolver() != null
) {
544 getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
547 getContentProviderClient().applyBatch(operations
);
550 } catch (OperationApplicationException e
) {
551 Log_OC
.e(TAG
, "Fail to update descendants of " + folder
.getFileId() + " in database", e
);
553 } catch (RemoteException e
) {
554 Log_OC
.e(TAG
, "Fail to update desendants of " + folder
.getFileId() + " in database", e
);
561 private Vector
<OCFile
> getFolderContent(long parentId
) {
563 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
565 Uri req_uri
= Uri
.withAppendedPath(
566 ProviderTableMeta
.CONTENT_URI_DIR
,
567 String
.valueOf(parentId
));
570 if (getContentProviderClient() != null
) {
572 c
= getContentProviderClient().query(req_uri
, null
,
573 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
574 new String
[] { String
.valueOf(parentId
)}, null
);
575 } catch (RemoteException e
) {
576 Log_OC
.e(TAG
, e
.getMessage());
580 c
= getContentResolver().query(req_uri
, null
,
581 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
582 new String
[] { String
.valueOf(parentId
)}, null
);
585 if (c
.moveToFirst()) {
587 OCFile child
= createFileInstance(c
);
589 } while (c
.moveToNext());
594 Collections
.sort(ret
);
600 private OCFile
createRootDir() {
601 OCFile file
= new OCFile(OCFile
.ROOT_PATH
);
602 file
.setMimetype("DIR");
603 file
.setParentId(FileDataStorageManager
.ROOT_PARENT_ID
);
608 private boolean fileExists(String cmp_key
, String value
) {
610 if (getContentResolver() != null
) {
611 c
= getContentResolver()
612 .query(ProviderTableMeta
.CONTENT_URI
,
615 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
617 new String
[] { value
, mAccount
.name
}, null
);
620 c
= getContentProviderClient().query(
621 ProviderTableMeta
.CONTENT_URI
,
624 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
625 new String
[] { value
, mAccount
.name
}, null
);
626 } catch (RemoteException e
) {
628 "Couldn't determine file existance, assuming non existance: "
633 boolean retval
= c
.moveToFirst();
638 private Cursor
getCursorForValue(String key
, String value
) {
640 if (getContentResolver() != null
) {
641 c
= getContentResolver()
642 .query(ProviderTableMeta
.CONTENT_URI
,
645 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
647 new String
[] { value
, mAccount
.name
}, null
);
650 c
= getContentProviderClient().query(
651 ProviderTableMeta
.CONTENT_URI
,
653 key
+ "=? AND " + ProviderTableMeta
.FILE_ACCOUNT_OWNER
654 + "=?", new String
[] { value
, mAccount
.name
},
656 } catch (RemoteException e
) {
657 Log_OC
.e(TAG
, "Could not get file details: " + e
.getMessage());
664 private OCFile
createFileInstance(Cursor c
) {
667 file
= new OCFile(c
.getString(c
668 .getColumnIndex(ProviderTableMeta
.FILE_PATH
)));
669 file
.setFileId(c
.getLong(c
.getColumnIndex(ProviderTableMeta
._ID
)));
670 file
.setParentId(c
.getLong(c
671 .getColumnIndex(ProviderTableMeta
.FILE_PARENT
)));
672 file
.setMimetype(c
.getString(c
673 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)));
674 if (!file
.isFolder()) {
675 file
.setStoragePath(c
.getString(c
676 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
)));
677 if (file
.getStoragePath() == null
) {
678 // 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
679 File f
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, file
));
681 file
.setStoragePath(f
.getAbsolutePath());
682 file
.setLastSyncDateForData(f
.lastModified());
686 file
.setFileLength(c
.getLong(c
687 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
)));
688 file
.setCreationTimestamp(c
.getLong(c
689 .getColumnIndex(ProviderTableMeta
.FILE_CREATION
)));
690 file
.setModificationTimestamp(c
.getLong(c
691 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED
)));
692 file
.setModificationTimestampAtLastSyncForData(c
.getLong(c
693 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
)));
694 file
.setLastSyncDateForProperties(c
.getLong(c
695 .getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE
)));
696 file
.setLastSyncDateForData(c
.getLong(c
.
697 getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
)));
698 file
.setKeepInSync(c
.getInt(
699 c
.getColumnIndex(ProviderTableMeta
.FILE_KEEP_IN_SYNC
)) == 1 ? true
: false
);
700 file
.setEtag(c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_ETAG
)));