Merge pull request #2433 from zhongwuzw/fix-cache-migration

Fix cache migration when dstPath intermediate directories not exist
This commit is contained in:
DreamPiggy 2018-08-10 15:49:11 +08:00 committed by GitHub
commit bbee2976af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -109,6 +109,7 @@
If the old location does not exist, does nothing.
If the new location does not exist, only do a movement of directory.
If the new location does exist, will move and merge the files from old location.
If the new location does exist, but is not a directory, will remove it and do a movement of directory.
@param srcPath old location of cache directory
@param dstPath new location of cache directory

View File

@ -246,6 +246,11 @@
// New path is not directory, remove file
[self.fileManager removeItemAtPath:dstPath error:nil];
}
NSString *dstParentPath = [dstPath stringByDeletingLastPathComponent];
// Creates any non-existent parent directories as part of creating the directory in path
if (![self.fileManager fileExistsAtPath:dstParentPath]) {
[self.fileManager createDirectoryAtPath:dstParentPath withIntermediateDirectories:YES attributes:nil error:NULL];
}
// New directory does not exist, rename directory
[self.fileManager moveItemAtPath:srcPath toPath:dstPath error:nil];
} else {
@ -253,7 +258,6 @@
NSDirectoryEnumerator *dirEnumerator = [self.fileManager enumeratorAtPath:srcPath];
NSString *file;
while ((file = [dirEnumerator nextObject])) {
// Don't handle error, just try to move.
[self.fileManager moveItemAtPath:[srcPath stringByAppendingPathComponent:file] toPath:[dstPath stringByAppendingPathComponent:file] error:nil];
}
// Remove the old path