From b90719b6cb1b5f09fd047ff61fe93003cbabb360 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 30 Oct 2012 16:26:11 +0300 Subject: [PATCH] Delete old "downloading" and "resume" files when Storage is initializing. --- iphone/Maps/Classes/MapsAppDelegate.mm | 12 ++++-------- storage/storage.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 21a7f577bb..261def3436 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -38,23 +38,19 @@ [fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:@"index.stamp"] error:nil]; [fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:@"index.idx"] error:nil]; - // Delete ".downloading" and ".resume" files and disable iCloud backup for downloaded ".mwm" maps + // Disable iCloud backup for downloaded ".mwm" maps. + char const * attrName = "com.apple.MobileBackup"; NSArray * files = [fileManager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil]; for (NSUInteger i = 0; i < [files count]; ++i) { NSString * fileName = [files objectAtIndex:i]; - if (([fileName rangeOfString:@".downloading"].location != NSNotFound) || - ([fileName rangeOfString:@".resume"].location != NSNotFound)) - { - [fileManager removeItemAtPath:[documentsDirectoryPath stringByAppendingPathComponent:fileName] error:nil]; - } - else if ([fileName rangeOfString:@".mwm"].location != NSNotFound) + if ([fileName rangeOfString:@DATA_FILE_EXTENSION].location != NSNotFound) { // Disable iCloud backup - static char const * attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr([[documentsDirectoryPath stringByAppendingPathComponent:fileName] UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0); + if (result == 0) NSLog(@"Disabled iCloud backup for %@", fileName); else diff --git a/storage/storage.cpp b/storage/storage.cpp index 674953770a..d47803f0a2 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -64,6 +64,18 @@ namespace storage Storage::Storage() : m_currentSlotId(0) { LoadCountriesFile(false); + + Platform & pl = GetPlatform(); + string const dir = pl.WritableDir(); + + // Delete all: .mwm.downloading; .mwm.downloading2; .mwm.resume; .mwm.resume2 + string const regexp = "\\" DATA_FILE_EXTENSION "\\.(downloading2?$|resume2?$)"; + + Platform::FilesList files; + pl.GetFilesByRegExp(dir, regexp, files); + + for (size_t j = 0; j < files.size(); ++j) + FileWriter::DeleteFileX(dir + files[j]); } ////////////////////////////////////////////////////////////////////////////