@@ -70,7 +70,7 @@ class FilesSyncWork(
7070 val changedFiles = inputData.getStringArray(CHANGED_FILES )
7171
7272 backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl .formatClassTag(this ::class ) + " _" + syncFolderId)
73- Log_OC .d(TAG , " File-sync worker started for folder ID: $syncFolderId " )
73+ Log_OC .d(TAG , " AutoUpload started folder ID: $syncFolderId " )
7474
7575 // Create all the providers we'll need
7676 val resources = context.resources
@@ -81,7 +81,7 @@ class FilesSyncWork(
8181 dateFormat.timeZone = TimeZone .getTimeZone(TimeZone .getDefault().id)
8282
8383 if (! setSyncedFolder(syncFolderId)) {
84- Log_OC .d (TAG , " File-sync kill worker since syncedFolder ($syncFolderId ) is not enabled!" )
84+ Log_OC .w (TAG , " AutoUpload skipped since syncedFolder ($syncFolderId ) is not enabled!" )
8585 return logEndOfWorker(syncFolderId)
8686 }
8787
@@ -97,6 +97,7 @@ class FilesSyncWork(
9797 )
9898
9999 if (canExitEarly(changedFiles, syncFolderId)) {
100+ Log_OC .w(TAG , " AutoUpload skipped canExit conditions are met" )
100101 return logEndOfWorker(syncFolderId)
101102 }
102103
@@ -108,11 +109,11 @@ class FilesSyncWork(
108109 // Get changed files from ContentObserverWork (only images and videos) or by scanning filesystem
109110 Log_OC .d(
110111 TAG ,
111- " File-sync worker (${syncedFolder.remotePath} ) changed files from observer: " +
112+ " AutoUpload (${syncedFolder.remotePath} ) changed files from observer: " +
112113 changedFiles.contentToString()
113114 )
114115 collectChangedFiles(changedFiles)
115- Log_OC .d(TAG , " File-sync worker (${syncedFolder.remotePath} ) finished checking files." )
116+ Log_OC .d(TAG , " AutoUpload (${syncedFolder.remotePath} ) finished checking files." )
116117
117118 uploadFilesFromFolder(
118119 context,
@@ -135,7 +136,7 @@ class FilesSyncWork(
135136 }
136137
137138 private fun logEndOfWorker (syncFolderId : Long ): Result {
138- Log_OC .d(TAG , " File-sync worker (${syncedFolder.remotePath} ) finished" )
139+ Log_OC .d(TAG , " AutoUpload worker (${syncedFolder.remotePath} ) finished" )
139140 val result = Result .success()
140141 backgroundJobManager.logEndOfWorker(
141142 BackgroundJobManagerImpl .formatClassTag(this ::class ) +
@@ -159,35 +160,37 @@ class FilesSyncWork(
159160 // If we are in power save mode better to postpone scan and upload
160161 val overridePowerSaving = inputData.getBoolean(OVERRIDE_POWER_SAVING , false )
161162 if ((powerManagementService.isPowerSavingEnabled && ! overridePowerSaving)) {
162- Log_OC .d (TAG , " File-sync kill worker since powerSaving is enabled!" )
163+ Log_OC .w (TAG , " AutoUpload skipped powerSaving is enabled!" )
163164 return true
164165 }
165166
166167 if (syncedFolderID < 0 ) {
167- Log_OC .d (TAG , " File-sync kill worker since no valid syncedFolderID provided! " )
168+ Log_OC .w (TAG , " AutoUpload skipped no valid syncedFolderID provided" )
168169 return true
169170 }
170171
171172 // or sync worker already running
172173 if (backgroundJobManager.bothFilesSyncJobsRunning(syncedFolderID)) {
173- Log_OC .d(
174- TAG ,
175- " File-sync kill worker since another instance of the worker " +
176- " ($syncedFolderID ) seems to be running already!"
177- )
174+ Log_OC .w(TAG , " AutoUpload skipped another worker instance is running for $syncedFolderID " )
178175 return true
179176 }
180177
181- val passedScanInterval = (
182- syncedFolder.lastScanTimestampMs +
183- FilesSyncHelper .calculateScanInterval(syncedFolder, connectivityService, powerManagementService)
184- ) <= System .currentTimeMillis()
178+ val calculatedScanInterval =
179+ FilesSyncHelper .calculateScanInterval(syncedFolder, connectivityService, powerManagementService)
180+ val totalScanInterval = (syncedFolder.lastScanTimestampMs + calculatedScanInterval)
181+ val currentTime = System .currentTimeMillis()
182+ val passedScanInterval = totalScanInterval <= currentTime
183+
184+ Log_OC .d(TAG , " AutoUpload lastScanTimestampMs: " + syncedFolder.lastScanTimestampMs)
185+ Log_OC .d(TAG , " AutoUpload calculatedScanInterval: $calculatedScanInterval " )
186+ Log_OC .d(TAG , " AutoUpload totalScanInterval: $totalScanInterval " )
187+ Log_OC .d(TAG , " AutoUpload currentTime: $currentTime " )
188+ Log_OC .d(TAG , " AutoUpload passedScanInterval: $passedScanInterval " )
185189
186190 if (! passedScanInterval && changedFiles.isNullOrEmpty() && ! overridePowerSaving) {
187- Log_OC .d (
191+ Log_OC .w (
188192 TAG ,
189- " File-sync kill worker since started before scan " +
190- " Interval and nothing todo (${syncedFolder.localPath} )!"
193+ " AutoUpload skipped since started before scan interval and nothing todo: " + syncedFolder.localPath
191194 )
192195 return true
193196 }
@@ -196,7 +199,10 @@ class FilesSyncWork(
196199 ! powerManagementService.battery.isCharging &&
197200 ! powerManagementService.battery.isFull
198201 ) {
199- Log_OC .d(TAG , " File-sync kill worker since phone is not charging (${syncedFolder.localPath} )!" )
202+ Log_OC .w(
203+ TAG ,
204+ " AutoUpload skipped since phone is not charging: " + syncedFolder.localPath
205+ )
200206 return true
201207 }
202208
@@ -233,6 +239,7 @@ class FilesSyncWork(
233239
234240 val optionalUser = userAccountManager.getUser(accountName)
235241 if (! optionalUser.isPresent) {
242+ Log_OC .w(TAG , " AutoUpload:uploadFilesFromFolder skipped user not present" )
236243 return
237244 }
238245
@@ -252,23 +259,34 @@ class FilesSyncWork(
252259 syncedFolder.id.toString()
253260 )
254261 if (paths.isEmpty()) {
262+ Log_OC .w(TAG , " AutoUpload:uploadFilesFromFolder skipped paths is empty" )
255263 return
256264 }
257265
258266 val pathsAndMimes = paths.map { path ->
259267 val file = File (path)
260268 val localPath = file.absolutePath
269+ val remotePath = getRemotePath(file, syncedFolder, sFormatter, lightVersion, resources, currentLocale)
270+ val mimeType = MimeTypeUtil .getBestMimeTypeByFilename(localPath)
271+
272+ Log_OC .d(TAG , " AutoUpload:pathsAndMimes file.path: ${file.path} " )
273+ Log_OC .d(TAG , " AutoUpload:pathsAndMimes localPath: $localPath " )
274+ Log_OC .d(TAG , " AutoUpload:pathsAndMimes remotePath: $remotePath " )
275+ Log_OC .d(TAG , " AutoUpload:pathsAndMimes mimeType: $mimeType " )
276+
261277 Triple (
262278 localPath,
263- getRemotePath(file, syncedFolder, sFormatter, lightVersion, resources, currentLocale) ,
264- MimeTypeUtil .getBestMimeTypeByFilename(localPath)
279+ remotePath ,
280+ mimeType
265281 )
266282 }
267283
268284 val localPaths = pathsAndMimes.map { it.first }.toTypedArray()
269285 val remotePaths = pathsAndMimes.map { it.second }.toTypedArray()
270286
271287 if (lightVersion) {
288+ Log_OC .d(TAG , " AutoUpload:uploadFilesFromFolder light version is used" )
289+
272290 needsCharging = resources.getBoolean(R .bool.syncedFolder_light_on_charging)
273291 needsWifi = arbitraryDataProvider?.getBooleanValue(
274292 accountName,
@@ -277,7 +295,10 @@ class FilesSyncWork(
277295
278296 val uploadActionString = resources.getString(R .string.syncedFolder_light_upload_behaviour)
279297 uploadAction = getUploadAction(uploadActionString)
298+ Log_OC .d(TAG , " AutoUpload upload action is: $uploadAction " )
280299 } else {
300+ Log_OC .d(TAG , " AutoUpload:uploadFilesFromFolder not light version is used" )
301+
281302 needsCharging = syncedFolder.isChargingOnly
282303 needsWifi = syncedFolder.isWifiOnly
283304 uploadAction = syncedFolder.uploadAction
@@ -287,7 +308,7 @@ class FilesSyncWork(
287308 user,
288309 localPaths,
289310 remotePaths,
290- uploadAction!! ,
311+ uploadAction,
291312 // create parent folder if not existent
292313 true ,
293314 UploadFileOperation .CREATED_AS_INSTANT_PICTURE ,
@@ -317,10 +338,14 @@ class FilesSyncWork(
317338 val useSubfolders: Boolean
318339 val subFolderRule: SubFolderRule
319340 if (lightVersion) {
341+ Log_OC .d(TAG , " AutoUpload:getRemotePath light version is used" )
342+
320343 useSubfolders = resources.getBoolean(R .bool.syncedFolder_light_use_subfolders)
321344 remoteFolder = resources.getString(R .string.syncedFolder_remote_folder)
322345 subFolderRule = SubFolderRule .YEAR_MONTH
323346 } else {
347+ Log_OC .d(TAG , " AutoUpload:getRemotePath not light version is used" )
348+
324349 useSubfolders = syncedFolder.isSubfolderByDate
325350 remoteFolder = syncedFolder.remotePath
326351 subFolderRule = syncedFolder.subfolderRule
@@ -348,6 +373,8 @@ class FilesSyncWork(
348373 ): Long {
349374 var lastModificationTime = file.lastModified()
350375 if (MediaFolderType .IMAGE == syncedFolder.type && hasExif(file)) {
376+ Log_OC .d(TAG , " AutoUpload:calculateLastModificationTime exif found" )
377+
351378 @Suppress(" TooGenericExceptionCaught" ) // legacy code
352379 try {
353380 val exifInterface = ExifInterface (file.absolutePath)
@@ -356,6 +383,9 @@ class FilesSyncWork(
356383 val pos = ParsePosition (0 )
357384 val dateTime = formatter.parse(exifDate, pos)
358385 lastModificationTime = dateTime.time
386+ Log_OC .w(TAG , " AutoUpload:calculateLastModificationTime calculatedTime is: $lastModificationTime " )
387+ } else {
388+ Log_OC .w(TAG , " AutoUpload:calculateLastModificationTime exifDate is empty" )
359389 }
360390 } catch (e: Exception ) {
361391 Log_OC .d(TAG , " Failed to get the proper time " + e.localizedMessage)
@@ -364,7 +394,7 @@ class FilesSyncWork(
364394 return lastModificationTime
365395 }
366396
367- private fun getUploadAction (action : String ): Int? {
397+ private fun getUploadAction (action : String ): Int {
368398 return when (action) {
369399 " LOCAL_BEHAVIOUR_FORGET" -> FileUploadWorker .LOCAL_BEHAVIOUR_FORGET
370400 " LOCAL_BEHAVIOUR_MOVE" -> FileUploadWorker .LOCAL_BEHAVIOUR_MOVE
0 commit comments