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
;
34 import android
.accounts
.Account
;
35 import android
.content
.ContentProviderClient
;
36 import android
.content
.ContentProviderOperation
;
37 import android
.content
.ContentProviderResult
;
38 import android
.content
.ContentResolver
;
39 import android
.content
.ContentUris
;
40 import android
.content
.ContentValues
;
41 import android
.content
.OperationApplicationException
;
42 import android
.database
.Cursor
;
43 import android
.net
.Uri
;
44 import android
.os
.RemoteException
;
46 public class FileDataStorageManager
{
48 public static final int ROOT_PARENT_ID
= 0;
50 private ContentResolver mContentResolver
;
51 private ContentProviderClient mContentProviderClient
;
52 private Account mAccount
;
54 private static String TAG
= FileDataStorageManager
.class.getSimpleName();
57 public FileDataStorageManager(Account account
, ContentResolver cr
) {
58 mContentProviderClient
= null
;
59 mContentResolver
= cr
;
63 public FileDataStorageManager(Account account
, ContentProviderClient cp
) {
64 mContentProviderClient
= cp
;
65 mContentResolver
= null
;
70 public void setAccount(Account account
) {
74 public Account
getAccount() {
78 public void setContentResolver(ContentResolver cr
) {
79 mContentResolver
= cr
;
82 public ContentResolver
getContentResolver() {
83 return mContentResolver
;
86 public void setContentProviderClient(ContentProviderClient cp
) {
87 mContentProviderClient
= cp
;
90 public ContentProviderClient
getContentProviderClient() {
91 return mContentProviderClient
;
95 public OCFile
getFileByPath(String path
) {
96 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_PATH
, path
);
98 if (c
.moveToFirst()) {
99 file
= createFileInstance(c
);
102 if (file
== null
&& OCFile
.ROOT_PATH
.equals(path
)) {
103 return createRootDir(); // root should always exist
109 public OCFile
getFileById(long id
) {
110 Cursor c
= getCursorForValue(ProviderTableMeta
._ID
, String
.valueOf(id
));
112 if (c
.moveToFirst()) {
113 file
= createFileInstance(c
);
119 public OCFile
getFileByLocalPath(String path
) {
120 Cursor c
= getCursorForValue(ProviderTableMeta
.FILE_STORAGE_PATH
, path
);
122 if (c
.moveToFirst()) {
123 file
= createFileInstance(c
);
129 public boolean fileExists(long id
) {
130 return fileExists(ProviderTableMeta
._ID
, String
.valueOf(id
));
133 public boolean fileExists(String path
) {
134 return fileExists(ProviderTableMeta
.FILE_PATH
, path
);
138 public Vector
<OCFile
> getFolderContent(OCFile f
) {
139 if (f
!= null
&& f
.isFolder() && f
.getFileId() != -1) {
140 return getFolderContent(f
.getFileId());
143 return new Vector
<OCFile
>();
148 public Vector
<OCFile
> getFolderImages(OCFile folder
) {
149 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
150 if (folder
!= null
) {
151 // TODO better implementation, filtering in the access to database (if possible) instead of here
152 Vector
<OCFile
> tmp
= getFolderContent(folder
);
153 OCFile current
= null
;
154 for (int i
=0; i
<tmp
.size(); i
++) {
155 current
= tmp
.get(i
);
156 if (current
.isImage()) {
165 public boolean saveFile(OCFile file
) {
166 boolean overriden
= false
;
167 ContentValues cv
= new ContentValues();
168 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
169 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
170 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
171 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
172 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
173 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
174 //if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
175 cv
.put(ProviderTableMeta
.FILE_PARENT
, file
.getParentId());
176 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
177 if (!file
.isFolder())
178 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
179 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
180 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
181 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
182 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
183 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
185 boolean sameRemotePath
= fileExists(file
.getRemotePath());
186 if (sameRemotePath
||
187 fileExists(file
.getFileId()) ) { // for renamed files; no more delete and create
189 OCFile oldFile
= null
;
190 if (sameRemotePath
) {
191 oldFile
= getFileByPath(file
.getRemotePath());
192 file
.setFileId(oldFile
.getFileId());
194 oldFile
= getFileById(file
.getFileId());
198 if (getContentResolver() != null
) {
199 getContentResolver().update(ProviderTableMeta
.CONTENT_URI
, cv
,
200 ProviderTableMeta
._ID
+ "=?",
201 new String
[] { String
.valueOf(file
.getFileId()) });
204 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI
,
205 cv
, ProviderTableMeta
._ID
+ "=?",
206 new String
[] { String
.valueOf(file
.getFileId()) });
207 } catch (RemoteException e
) {
209 "Fail to insert insert file to database "
214 Uri result_uri
= null
;
215 if (getContentResolver() != null
) {
216 result_uri
= getContentResolver().insert(
217 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
220 result_uri
= getContentProviderClient().insert(
221 ProviderTableMeta
.CONTENT_URI_FILE
, cv
);
222 } catch (RemoteException e
) {
224 "Fail to insert insert file to database "
228 if (result_uri
!= null
) {
229 long new_id
= Long
.parseLong(result_uri
.getPathSegments()
231 file
.setFileId(new_id
);
235 if (file
.isFolder()) {
236 updateFolderSize(file
.getFileId());
238 updateFolderSize(file
.getParentId());
246 * Inserts or updates the list of files contained in a given folder.
248 * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD.
249 * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED
253 * @param removeNotUpdated
255 public void saveFolder(OCFile folder
, Collection
<OCFile
> updatedFiles
, Collection
<OCFile
> filesToRemove
) {
257 Log_OC
.d(TAG
, "Saving folder " + folder
.getRemotePath() + " with " + updatedFiles
.size() + " children and " + filesToRemove
.size() + " files to remove");
259 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(updatedFiles
.size());
261 // prepare operations to insert or update files to save in the given folder
262 for (OCFile file
: updatedFiles
) {
263 ContentValues cv
= new ContentValues();
264 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, file
.getModificationTimestamp());
265 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, file
.getModificationTimestampAtLastSyncForData());
266 cv
.put(ProviderTableMeta
.FILE_CREATION
, file
.getCreationTimestamp());
267 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, file
.getFileLength());
268 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, file
.getMimetype());
269 cv
.put(ProviderTableMeta
.FILE_NAME
, file
.getFileName());
270 //cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
271 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getFileId());
272 cv
.put(ProviderTableMeta
.FILE_PATH
, file
.getRemotePath());
273 if (!file
.isFolder()) {
274 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, file
.getStoragePath());
276 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
277 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, file
.getLastSyncDateForProperties());
278 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, file
.getLastSyncDateForData());
279 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, file
.keepInSync() ?
1 : 0);
280 cv
.put(ProviderTableMeta
.FILE_ETAG
, file
.getEtag());
282 boolean existsByPath
= fileExists(file
.getRemotePath());
283 if (existsByPath
|| fileExists(file
.getFileId())) {
284 // updating an existing file
285 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
287 withSelection( ProviderTableMeta
._ID
+ "=?",
288 new String
[] { String
.valueOf(file
.getFileId()) })
293 operations
.add(ContentProviderOperation
.newInsert(ProviderTableMeta
.CONTENT_URI
).withValues(cv
).build());
297 // prepare operations to remove files in the given folder
298 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
299 String
[] whereArgs
= null
;
300 for (OCFile file
: filesToRemove
) {
301 if (file
.getParentId() == folder
.getFileId()) {
302 whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
303 //Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, "" + file.getFileId());
304 if (file
.isFolder()) {
305 operations
.add(ContentProviderOperation
306 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_DIR
, file
.getFileId())).withSelection(where
, whereArgs
)
308 // TODO remove local folder
310 operations
.add(ContentProviderOperation
311 .newDelete(ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId())).withSelection(where
, whereArgs
)
314 new File(file
.getStoragePath()).delete();
315 // TODO move the deletion of local contents after success of deletions
321 // update metadata of folder
322 ContentValues cv
= new ContentValues();
323 cv
.put(ProviderTableMeta
.FILE_MODIFIED
, folder
.getModificationTimestamp());
324 cv
.put(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
, folder
.getModificationTimestampAtLastSyncForData());
325 cv
.put(ProviderTableMeta
.FILE_CREATION
, folder
.getCreationTimestamp());
326 cv
.put(ProviderTableMeta
.FILE_CONTENT_LENGTH
, 0); // FileContentProvider calculates the right size
327 cv
.put(ProviderTableMeta
.FILE_CONTENT_TYPE
, folder
.getMimetype());
328 cv
.put(ProviderTableMeta
.FILE_NAME
, folder
.getFileName());
329 cv
.put(ProviderTableMeta
.FILE_PARENT
, folder
.getParentId());
330 cv
.put(ProviderTableMeta
.FILE_PATH
, folder
.getRemotePath());
331 cv
.put(ProviderTableMeta
.FILE_ACCOUNT_OWNER
, mAccount
.name
);
332 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE
, folder
.getLastSyncDateForProperties());
333 cv
.put(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
, folder
.getLastSyncDateForData());
334 cv
.put(ProviderTableMeta
.FILE_KEEP_IN_SYNC
, folder
.keepInSync() ?
1 : 0);
335 cv
.put(ProviderTableMeta
.FILE_ETAG
, folder
.getEtag());
336 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
338 withSelection( ProviderTableMeta
._ID
+ "=?",
339 new String
[] { String
.valueOf(folder
.getFileId()) })
342 // apply operations in batch
343 ContentProviderResult
[] results
= null
;
344 Log_OC
.d(TAG
, "Sending " + operations
.size() + " operations to FileContentProvider");
346 if (getContentResolver() != null
) {
347 results
= getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
350 results
= getContentProviderClient().applyBatch(operations
);
353 } catch (OperationApplicationException e
) {
354 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
356 } catch (RemoteException e
) {
357 Log_OC
.e(TAG
, "Exception in batch of operations " + e
.getMessage());
360 // update new id in file objects for insertions
361 if (results
!= null
) {
363 Iterator
<OCFile
> filesIt
= updatedFiles
.iterator();
365 for (int i
=0; i
<results
.length
; i
++) {
366 if (filesIt
.hasNext()) {
367 file
= filesIt
.next();
371 if (results
[i
].uri
!= null
) {
372 newId
= Long
.parseLong(results
[i
].uri
.getPathSegments().get(1));
373 //updatedFiles.get(i).setFileId(newId);
375 file
.setFileId(newId
);
381 updateFolderSize(folder
.getFileId());
390 private void updateFolderSize(long id
) {
391 if (id
> FileDataStorageManager
.ROOT_PARENT_ID
) {
392 Log_OC
.d(TAG
, "Updating size of " + id
);
393 if (getContentResolver() != null
) {
394 getContentResolver().update(ProviderTableMeta
.CONTENT_URI_DIR
, null
,
395 ProviderTableMeta
._ID
+ "=?",
396 new String
[] { String
.valueOf(id
) });
399 getContentProviderClient().update(ProviderTableMeta
.CONTENT_URI_DIR
, null
,
400 ProviderTableMeta
._ID
+ "=?",
401 new String
[] { String
.valueOf(id
) });
403 } catch (RemoteException e
) {
404 Log_OC
.e(TAG
, "Exception in update of folder size through compatibility patch " + e
.getMessage());
408 Log_OC
.e(TAG
, "not updating size for folder " + id
);
413 public void removeFile(OCFile file
, boolean removeDBData
, boolean removeLocalCopy
) {
415 if (file
.isFolder()) {
416 removeFolder(file
, removeDBData
, removeLocalCopy
);
420 //Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
421 Uri file_uri
= ContentUris
.withAppendedId(ProviderTableMeta
.CONTENT_URI_FILE
, file
.getFileId());
422 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
423 String
[] whereArgs
= new String
[]{mAccount
.name
, file
.getRemotePath()};
424 if (getContentProviderClient() != null
) {
426 getContentProviderClient().delete(file_uri
, where
, whereArgs
);
427 } catch (RemoteException e
) {
431 getContentResolver().delete(file_uri
, where
, whereArgs
);
433 updateFolderSize(file
.getParentId());
435 if (removeLocalCopy
&& file
.isDown()) {
436 boolean success
= new File(file
.getStoragePath()).delete();
437 if (!removeDBData
&& success
) {
438 // maybe unnecessary, but should be checked TODO remove if unnecessary
439 file
.setStoragePath(null
);
448 public void removeFolder(OCFile folder
, boolean removeDBData
, boolean removeLocalContent
) {
449 if (folder
!= null
&& folder
.isFolder()) {
450 if (removeDBData
&& folder
.getFileId() != -1) {
451 removeFolderInDb(folder
);
453 if (removeLocalContent
) {
454 File localFolder
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, folder
));
455 removeLocalFolder(localFolder
);
460 private void removeFolderInDb(OCFile folder
) {
461 Uri folder_uri
= Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_DIR
, ""+ folder
.getFileId()); // URI for recursive deletion
462 String where
= ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?" + " AND " + ProviderTableMeta
.FILE_PATH
+ "=?";
463 String
[] whereArgs
= new String
[]{mAccount
.name
, folder
.getRemotePath()};
464 if (getContentProviderClient() != null
) {
466 getContentProviderClient().delete(folder_uri
, where
, whereArgs
);
467 } catch (RemoteException e
) {
471 getContentResolver().delete(folder_uri
, where
, whereArgs
);
473 updateFolderSize(folder
.getParentId());
476 private void removeLocalFolder(File folder
) {
477 if (folder
.exists()) {
478 File
[] files
= folder
.listFiles();
480 for (File file
: files
) {
481 if (file
.isDirectory()) {
482 removeLocalFolder(file
);
493 * Updates database for a folder that was moved to a different location.
495 * TODO explore better (faster) implementations
496 * TODO throw exceptions up !
498 public void moveFolder(OCFile folder
, String newPath
) {
499 // TODO check newPath
501 if (folder
!= null
&& folder
.isFolder() && folder
.fileExists() && !OCFile
.ROOT_PATH
.equals(folder
.getFileName())) {
502 /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
504 if (getContentProviderClient() != null
) {
506 c
= getContentProviderClient().query(ProviderTableMeta
.CONTENT_URI
,
508 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
509 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
510 } catch (RemoteException e
) {
511 Log_OC
.e(TAG
, e
.getMessage());
514 c
= getContentResolver().query(ProviderTableMeta
.CONTENT_URI
,
516 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=? AND " + ProviderTableMeta
.FILE_PATH
+ " LIKE ? ",
517 new String
[] { mAccount
.name
, folder
.getRemotePath() + "%" }, ProviderTableMeta
.FILE_PATH
+ " ASC ");
520 /// 2. prepare a batch of update operations to change all the descendants
521 ArrayList
<ContentProviderOperation
> operations
= new ArrayList
<ContentProviderOperation
>(c
.getCount());
522 int lengthOfOldPath
= folder
.getRemotePath().length();
523 String defaultSavePath
= FileStorageUtils
.getSavePath(mAccount
.name
);
524 int lengthOfOldStoragePath
= defaultSavePath
.length() + lengthOfOldPath
;
525 if (c
.moveToFirst()) {
527 ContentValues cv
= new ContentValues(); // don't take the constructor out of the loop and clear the object
528 OCFile child
= createFileInstance(c
);
529 cv
.put(ProviderTableMeta
.FILE_PATH
, newPath
+ child
.getRemotePath().substring(lengthOfOldPath
));
530 if (child
.getStoragePath() != null
&& child
.getStoragePath().startsWith(defaultSavePath
)) {
531 cv
.put(ProviderTableMeta
.FILE_STORAGE_PATH
, defaultSavePath
+ newPath
+ child
.getStoragePath().substring(lengthOfOldStoragePath
));
533 operations
.add(ContentProviderOperation
.newUpdate(ProviderTableMeta
.CONTENT_URI
).
535 withSelection( ProviderTableMeta
._ID
+ "=?",
536 new String
[] { String
.valueOf(child
.getFileId()) })
538 } while (c
.moveToNext());
542 /// 3. apply updates in batch
544 if (getContentResolver() != null
) {
545 getContentResolver().applyBatch(MainApp
.getAuthority(), operations
);
548 getContentProviderClient().applyBatch(operations
);
551 } catch (OperationApplicationException e
) {
552 Log_OC
.e(TAG
, "Fail to update descendants of " + folder
.getFileId() + " in database", e
);
554 } catch (RemoteException e
) {
555 Log_OC
.e(TAG
, "Fail to update desendants of " + folder
.getFileId() + " in database", e
);
562 private Vector
<OCFile
> getFolderContent(long parentId
) {
564 Vector
<OCFile
> ret
= new Vector
<OCFile
>();
566 Uri req_uri
= Uri
.withAppendedPath(
567 ProviderTableMeta
.CONTENT_URI_DIR
,
568 String
.valueOf(parentId
));
571 if (getContentProviderClient() != null
) {
573 c
= getContentProviderClient().query(req_uri
, null
,
574 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
575 new String
[] { String
.valueOf(parentId
)}, null
);
576 } catch (RemoteException e
) {
577 Log_OC
.e(TAG
, e
.getMessage());
581 c
= getContentResolver().query(req_uri
, null
,
582 ProviderTableMeta
.FILE_PARENT
+ "=?" ,
583 new String
[] { String
.valueOf(parentId
)}, null
);
586 if (c
.moveToFirst()) {
588 OCFile child
= createFileInstance(c
);
590 } while (c
.moveToNext());
595 Collections
.sort(ret
);
601 private OCFile
createRootDir() {
602 OCFile file
= new OCFile(OCFile
.ROOT_PATH
);
603 file
.setMimetype("DIR");
604 file
.setParentId(FileDataStorageManager
.ROOT_PARENT_ID
);
609 private boolean fileExists(String cmp_key
, String value
) {
611 if (getContentResolver() != null
) {
612 c
= getContentResolver()
613 .query(ProviderTableMeta
.CONTENT_URI
,
616 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
618 new String
[] { value
, mAccount
.name
}, null
);
621 c
= getContentProviderClient().query(
622 ProviderTableMeta
.CONTENT_URI
,
625 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
+ "=?",
626 new String
[] { value
, mAccount
.name
}, null
);
627 } catch (RemoteException e
) {
629 "Couldn't determine file existance, assuming non existance: "
634 boolean retval
= c
.moveToFirst();
639 private Cursor
getCursorForValue(String key
, String value
) {
641 if (getContentResolver() != null
) {
642 c
= getContentResolver()
643 .query(ProviderTableMeta
.CONTENT_URI
,
646 + ProviderTableMeta
.FILE_ACCOUNT_OWNER
648 new String
[] { value
, mAccount
.name
}, null
);
651 c
= getContentProviderClient().query(
652 ProviderTableMeta
.CONTENT_URI
,
654 key
+ "=? AND " + ProviderTableMeta
.FILE_ACCOUNT_OWNER
655 + "=?", new String
[] { value
, mAccount
.name
},
657 } catch (RemoteException e
) {
658 Log_OC
.e(TAG
, "Could not get file details: " + e
.getMessage());
665 private OCFile
createFileInstance(Cursor c
) {
668 file
= new OCFile(c
.getString(c
669 .getColumnIndex(ProviderTableMeta
.FILE_PATH
)));
670 file
.setFileId(c
.getLong(c
.getColumnIndex(ProviderTableMeta
._ID
)));
671 file
.setParentId(c
.getLong(c
672 .getColumnIndex(ProviderTableMeta
.FILE_PARENT
)));
673 file
.setMimetype(c
.getString(c
674 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
)));
675 if (!file
.isFolder()) {
676 file
.setStoragePath(c
.getString(c
677 .getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
)));
678 if (file
.getStoragePath() == null
) {
679 // 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
680 File f
= new File(FileStorageUtils
.getDefaultSavePathFor(mAccount
.name
, file
));
682 file
.setStoragePath(f
.getAbsolutePath());
683 file
.setLastSyncDateForData(f
.lastModified());
687 file
.setFileLength(c
.getLong(c
688 .getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
)));
689 file
.setCreationTimestamp(c
.getLong(c
690 .getColumnIndex(ProviderTableMeta
.FILE_CREATION
)));
691 file
.setModificationTimestamp(c
.getLong(c
692 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED
)));
693 file
.setModificationTimestampAtLastSyncForData(c
.getLong(c
694 .getColumnIndex(ProviderTableMeta
.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA
)));
695 file
.setLastSyncDateForProperties(c
.getLong(c
696 .getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE
)));
697 file
.setLastSyncDateForData(c
.getLong(c
.
698 getColumnIndex(ProviderTableMeta
.FILE_LAST_SYNC_DATE_FOR_DATA
)));
699 file
.setKeepInSync(c
.getInt(
700 c
.getColumnIndex(ProviderTableMeta
.FILE_KEEP_IN_SYNC
)) == 1 ? true
: false
);
701 file
.setEtag(c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_ETAG
)));