@@ -121,10 +121,14 @@ class BackupJob: BaseJob {
121121 for filename in localPaths {
122122 let localURL = AttachmentContainer . url. appendingPathComponent ( filename)
123123 let cloudURL = backupUrl. appendingPathComponent ( filename)
124- let localFileSize = FileManager . default. fileSize ( localURL. path)
125124 let cloudExists = FileManager . default. fileExists ( atPath: cloudURL. path)
126-
127- if !cloudExists || FileManager . default. fileSize ( cloudURL. path) != localFileSize || ( !cloudURL. isUploaded && !cloudURL. isUploading) {
125+ let cloudFileSize = FileManager . default. fileSize ( cloudURL. path)
126+ let localFileSize = FileManager . default. fileSize ( localURL. path)
127+ let isFileUploading = cloudURL. isUploaded || cloudURL. isUploading
128+ // 1. Cloud file doesn't exist.
129+ // 2. Cloud file size is different from the local file size.
130+ // 3. File has not been uploaded and is currently not uploading.
131+ if !cloudExists || cloudFileSize != localFileSize || !isFileUploading {
128132 backupPaths. append ( filename)
129133 backupTotalSize += localFileSize
130134 }
@@ -134,15 +138,16 @@ class BackupJob: BaseJob {
134138 totalFileSize += localFileSize
135139 }
136140
137- let databaseFileSize = getDatabaseFileSize ( )
141+ let localDatabaseSize = getDatabaseFileSize ( )
138142 let databaseCloudURL = backupUrl. appendingPathComponent ( backupDatabaseName)
139- let isBackupDatabase = !FileManager. default. fileExists ( atPath: databaseCloudURL. path)
140- || FileManager . default. fileSize ( databaseCloudURL. path) != databaseFileSize
141- || ( !databaseCloudURL. isUploaded && !databaseCloudURL. isUploading)
143+ let cloudDatabaseExists = FileManager . default. fileExists ( atPath: databaseCloudURL. path)
144+ let cloudDatabaseSize = FileManager . default. fileSize ( databaseCloudURL. path)
145+ let isDatabaseUploading = databaseCloudURL. isUploaded || databaseCloudURL. isUploading
146+ let isBackupDatabase = !cloudDatabaseExists || cloudDatabaseSize != localDatabaseSize || !isDatabaseUploading
142147
143148 if !isBackupDatabase {
144- withoutUploadSize += databaseFileSize
145- totalFileSize += databaseFileSize
149+ withoutUploadSize += localDatabaseSize
150+ totalFileSize += localDatabaseSize
146151 }
147152
148153 guard isContinueBackup else {
0 commit comments