Merge pull request #2433 from zhongwuzw/fix-cache-migration
Fix cache migration when dstPath intermediate directories not exist
This commit is contained in:
commit
bbee2976af
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue