Explorar o código

- delay job execution by minimal 10s
- on job execution: check if file exists prior to real upload. If file does not exist anymore, just ignore it

tobiasKaminsky %!s(int64=8) %!d(string=hai) anos
pai
achega
5ab691154e

+ 16 - 12
src/com/owncloud/android/services/SyncedFolderJobService.java

@@ -70,19 +70,23 @@ public class SyncedFolderJobService extends JobService {
         Log_OC.d(TAG, "startJob: " + params.getJobId() + ", filePath: " + filePath);
 
         File file = new File(filePath);
-        String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
 
-        FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
-        requester.uploadNewFile(
-                context,
-                account,
-                filePath,
-                FileStorageUtils.getInstantUploadFilePath(remoteFolder, file.getName(), dateTaken, subfolderByDate),
-                uploadBehaviour,
-                mimeType,
-                true,           // create parent folder if not existent
-                UploadFileOperation.CREATED_AS_INSTANT_PICTURE
-        );
+        // File can be deleted between job generation and job execution. If file does not exist, just ignore it
+        if (file.exists()) {
+            String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
+
+            FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
+            requester.uploadNewFile(
+                    context,
+                    account,
+                    filePath,
+                    FileStorageUtils.getInstantUploadFilePath(remoteFolder, file.getName(), dateTaken, subfolderByDate),
+                    uploadBehaviour,
+                    mimeType,
+                    true,           // create parent folder if not existent
+                    UploadFileOperation.CREATED_AS_INSTANT_PICTURE
+            );
+        }
         return false;
     }
 

+ 1 - 0
src/com/owncloud/android/services/observer/SyncedFolderObserver.java

@@ -61,6 +61,7 @@ class SyncedFolderObserver extends RecursiveFileObserver {
                     date.intValue(),
                     new ComponentName(context, SyncedFolderJobService.class))
                     .setRequiresCharging(syncedFolder.getChargingOnly())
+                    .setMinimumLatency(10000)
                     .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
                     .setExtras(bundle)
                     .setPersisted(true)