Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyu committed Apr 19, 2023
1 parent 39af3cc commit c80e213
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Mixin/Service/Job/BackupJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ class BackupJob: BaseJob {
for filename in localPaths {
let localURL = AttachmentContainer.url.appendingPathComponent(filename)
let cloudURL = backupUrl.appendingPathComponent(filename)
let localFileSize = FileManager.default.fileSize(localURL.path)
let cloudExists = FileManager.default.fileExists(atPath: cloudURL.path)

if !cloudExists || FileManager.default.fileSize(cloudURL.path) != localFileSize || (!cloudURL.isUploaded && !cloudURL.isUploading) {
let cloudFileSize = FileManager.default.fileSize(cloudURL.path)
let localFileSize = FileManager.default.fileSize(localURL.path)
let isFileUploading = cloudURL.isUploaded || cloudURL.isUploading
// 1. Cloud file doesn't exist.
// 2. Cloud file size is different from the local file size.
// 3. File has not been uploaded and is currently not uploading.
if !cloudExists || cloudFileSize != localFileSize || !isFileUploading {
backupPaths.append(filename)
backupTotalSize += localFileSize
}
Expand All @@ -134,15 +138,16 @@ class BackupJob: BaseJob {
totalFileSize += localFileSize
}

let databaseFileSize = getDatabaseFileSize()
let localDatabaseSize = getDatabaseFileSize()
let databaseCloudURL = backupUrl.appendingPathComponent(backupDatabaseName)
let isBackupDatabase = !FileManager.default.fileExists(atPath: databaseCloudURL.path)
|| FileManager.default.fileSize(databaseCloudURL.path) != databaseFileSize
|| (!databaseCloudURL.isUploaded && !databaseCloudURL.isUploading)
let cloudDatabaseExists = FileManager.default.fileExists(atPath: databaseCloudURL.path)
let cloudDatabaseSize = FileManager.default.fileSize(databaseCloudURL.path)
let isDatabaseUploading = databaseCloudURL.isUploaded || databaseCloudURL.isUploading
let isBackupDatabase = !cloudDatabaseExists || cloudDatabaseSize != localDatabaseSize || !isDatabaseUploading

if !isBackupDatabase {
withoutUploadSize += databaseFileSize
totalFileSize += databaseFileSize
withoutUploadSize += localDatabaseSize
totalFileSize += localDatabaseSize
}

guard isContinueBackup else {
Expand Down

0 comments on commit c80e213

Please sign in to comment.