Skip to content

Commit 2f17bc0

Browse files
Use decomposed file names for lookups
Build a decomposed-key map for local files and use Unicode-decomposed keys when matching local and remote file names. Added _localFilesWithDecomposedNames and populated it in the initializer. Replaced direct _localFiles lookups with decomposed-key lookups and normalized local keys before checking _uniqueRemoteFilesWithDecomposedNames. Also updated logging to use the decomposed-key map. This prevents mismatches caused by Unicode normalization differences between local and remote file name representations.
1 parent 71ccd14 commit 2f17bc0

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Sources/Backup/OAGenerateBackupInfoTask.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@implementation OAGenerateBackupInfoTask
2020
{
2121
NSDictionary<NSString *, OALocalFile *> *_localFiles;
22+
NSDictionary<NSString *, OALocalFile *> *_localFilesWithDecomposedNames;
2223
NSDictionary<NSString *, OARemoteFile *> *_uniqueRemoteFiles;
2324
NSDictionary<NSString *, OARemoteFile *> *_uniqueRemoteFilesWithDecomposedNames;
2425
NSDictionary<NSString *, OARemoteFile *> *_deletedRemoteFiles;
@@ -36,6 +37,13 @@ - (instancetype) initWithLocalFiles:(NSDictionary<NSString *, OALocalFile *> *)l
3637
if (self)
3738
{
3839
_localFiles = localFiles;
40+
NSMutableDictionary<NSString *, OALocalFile *> *decomposedLocalFiles = [NSMutableDictionary dictionaryWithCapacity:_localFiles.count];
41+
for (NSString *originalKey in _localFiles)
42+
{
43+
NSString *decomposedKey = [originalKey decomposedStringWithCanonicalMapping];
44+
decomposedLocalFiles[decomposedKey] = _localFiles[originalKey];
45+
}
46+
_localFilesWithDecomposedNames = decomposedLocalFiles;
3947
_uniqueRemoteFiles = uniqueRemoteFiles;
4048
NSMutableDictionary<NSString *, OARemoteFile *>* localMap = [NSMutableDictionary dictionaryWithCapacity:_uniqueRemoteFiles.count];
4149
for (NSString *originalKey in _uniqueRemoteFiles)
@@ -88,7 +96,7 @@ - (OABackupInfo *) doInBackground
8896
if (exportType == nil || ![OAExportSettingsType isTypeEnabled:exportType] || remoteFile.isRecordedVoiceFile)
8997
continue;
9098
NSString* decomposedRemoteName = remoteFile.getTypeNamePath.decomposedStringWithCanonicalMapping;
91-
OALocalFile *localFile = _localFiles[decomposedRemoteName];
99+
OALocalFile *localFile = _localFilesWithDecomposedNames[decomposedRemoteName];
92100
if (localFile != nil)
93101
{
94102
BOOL fileChangedLocally = localFile.localModifiedTime > localFile.uploadTime;
@@ -133,7 +141,8 @@ - (OABackupInfo *) doInBackground
133141
: nil;
134142
if (exportType == nil || ![OAExportSettingsType isTypeEnabled:exportType])
135143
continue;
136-
BOOL hasRemoteFile = _uniqueRemoteFilesWithDecomposedNames[localFile.getTypeFileName] != nil;
144+
NSString *localKeyNfd = localFile.getTypeFileName.decomposedStringWithCanonicalMapping;
145+
BOOL hasRemoteFile = _uniqueRemoteFilesWithDecomposedNames[localKeyNfd] != nil;
137146
BOOL fileToDelete = [info.localFilesToDelete containsObject:localFile];
138147
if (!hasRemoteFile && !fileToDelete)
139148
{
@@ -153,7 +162,7 @@ - (OABackupInfo *) doInBackground
153162
[_operationLog log:@"=== filesToDownload ==="];
154163
for (OARemoteFile *remoteFile in info.filesToDownload)
155164
{
156-
OALocalFile *localFile = _localFiles[remoteFile.getTypeNamePath];
165+
OALocalFile *localFile = _localFilesWithDecomposedNames[remoteFile.getTypeNamePath.decomposedStringWithCanonicalMapping];
157166
if (localFile)
158167
[_operationLog log:[NSString stringWithFormat:@"%@ localUploadTime=%ld", remoteFile.toString, localFile.uploadTime]];
159168
else

0 commit comments

Comments
 (0)