Merge lp:~threeve/ubuntuone-ios-music/fix-storage-locations into lp:ubuntuone-ios-music

Proposed by Jason Foreman
Status: Merged
Approved by: Zachery Bir
Approved revision: 221
Merged at revision: 218
Proposed branch: lp:~threeve/ubuntuone-ios-music/fix-storage-locations
Merge into: lp:ubuntuone-ios-music
Diff against target: 128 lines (+28/-9)
5 files modified
Other Sources/U1MusicAppDelegate.m (+1/-1)
utilities/Globals.h (+1/-0)
utilities/Globals.m (+15/-4)
utilities/U1CacheFileManager.m (+1/-1)
view_controllers/U1MigrationViewController.m (+10/-3)
To merge this branch: bzr merge lp:~threeve/ubuntuone-ios-music/fix-storage-locations
Reviewer Review Type Date Requested Status
Zachery Bir Approve
Review via email: mp+95199@code.launchpad.net

Description of the change

Change location of offline music cache and album art cache to more closely align with Apple's document storage guidelines.

To post a comment you must log in.
220. By Jason Foreman

Put album art in the cache directory.

221. By Jason Foreman

Temp downloads go to caches.

Revision history for this message
Zachery Bir (urbanape) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Other Sources/U1MusicAppDelegate.m'
2--- Other Sources/U1MusicAppDelegate.m 2012-02-17 17:55:54 +0000
3+++ Other Sources/U1MusicAppDelegate.m 2012-02-29 16:58:20 +0000
4@@ -71,7 +71,7 @@
5 [window makeKeyAndVisible];
6
7 NSFileManager *fileManager = [[NSFileManager alloc] init];
8- NSString *oldCacheDirectoryPath = [CachedMusicDirectory() path];
9+ NSString *oldCacheDirectoryPath = [[ApplicationDocumentsDirectory() URLByAppendingPathComponent:@"cached_music"] path];
10 if ([fileManager fileExistsAtPath:oldCacheDirectoryPath])
11 {
12 dispatch_async(dispatch_get_main_queue(), ^{
13
14=== modified file 'utilities/Globals.h'
15--- utilities/Globals.h 2012-02-09 17:50:11 +0000
16+++ utilities/Globals.h 2012-02-29 16:58:20 +0000
17@@ -20,6 +20,7 @@
18 #import <Foundation/Foundation.h>
19
20 NSURL* ApplicationDocumentsDirectory( void );
21+NSURL* ApplicationPrivateDocumentsDirectory( void );
22 NSURL* ApplicationCachesDirectory( void );
23 NSURL* DatabaseFile( void );
24 NSURL* TemporaryDownloadsDirectory( void );
25
26=== modified file 'utilities/Globals.m'
27--- utilities/Globals.m 2012-02-09 17:50:11 +0000
28+++ utilities/Globals.m 2012-02-29 16:58:20 +0000
29@@ -24,6 +24,17 @@
30 return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
31 }
32
33+NSURL* ApplicationPrivateDocumentsDirectory( void )
34+{
35+ NSURL *documentsDirectoryURL = [[[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:@"Private Documents"];
36+ NSFileManager *fm = [NSFileManager defaultManager];
37+ if (![fm fileExistsAtPath:[documentsDirectoryURL path]])
38+ {
39+ [fm createDirectoryAtPath:[documentsDirectoryURL path] withIntermediateDirectories:YES attributes:nil error:NULL];
40+ }
41+ return documentsDirectoryURL;
42+}
43+
44 NSURL* ApplicationCachesDirectory( void )
45 {
46 return [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
47@@ -31,13 +42,13 @@
48
49 NSURL* DatabaseFile( void )
50 {
51- NSURL* docs = ApplicationDocumentsDirectory();
52+ NSURL* docs = ApplicationPrivateDocumentsDirectory();
53 return [docs URLByAppendingPathComponent:@"music.sqlite"];
54 }
55
56 NSURL* TemporaryDownloadsDirectory( void )
57 {
58- NSURL* docs = ApplicationDocumentsDirectory();
59+ NSURL* docs = ApplicationCachesDirectory();
60 return [docs URLByAppendingPathComponent:@"tmp"];
61 }
62
63@@ -48,7 +59,7 @@
64
65 NSURL* CachedMusicDirectory( void )
66 {
67- NSURL* docs = ApplicationDocumentsDirectory();
68+ NSURL* docs = ApplicationPrivateDocumentsDirectory();
69 return [docs URLByAppendingPathComponent:@"cached_music"];
70 }
71
72@@ -59,7 +70,7 @@
73
74 NSURL* CachedAlbumArtDirectory( void )
75 {
76- NSURL* docs = ApplicationDocumentsDirectory();
77+ NSURL* docs = ApplicationCachesDirectory();
78 return [docs URLByAppendingPathComponent:@"cached_album_art"];
79 }
80
81
82=== modified file 'utilities/U1CacheFileManager.m'
83--- utilities/U1CacheFileManager.m 2012-02-22 18:04:28 +0000
84+++ utilities/U1CacheFileManager.m 2012-02-29 16:58:20 +0000
85@@ -71,7 +71,7 @@
86 }
87
88 self.cacheDirectory = [[ApplicationCachesDirectory() URLByAppendingPathComponent:@"cached_music"] path];
89- self.offlineDirectory = [[ApplicationDocumentsDirectory() URLByAppendingPathComponent:@"offline_music"] path];
90+ self.offlineDirectory = [[ApplicationPrivateDocumentsDirectory() URLByAppendingPathComponent:@"offline_music"] path];
91 writers = [[NSMutableDictionary alloc] init];
92 readers = [[NSMutableDictionary alloc] init];
93
94
95=== modified file 'view_controllers/U1MigrationViewController.m'
96--- view_controllers/U1MigrationViewController.m 2012-02-16 17:59:47 +0000
97+++ view_controllers/U1MigrationViewController.m 2012-02-29 16:58:20 +0000
98@@ -36,20 +36,27 @@
99 {
100 NSFileManager *fileManager = [[NSFileManager alloc] init];
101 U1CacheFileManager *cacheFileManager = [U1CacheFileManager sharedCacheFileManager];
102- NSString *oldCacheDirectoryPath = [CachedMusicDirectory() path];
103+ NSString *oldCacheDirectoryPath = [[ApplicationDocumentsDirectory() URLByAppendingPathComponent:@"cached_music"] path];
104
105 NSError *error = nil;
106 NSArray *songPaths = [fileManager contentsOfDirectoryAtPath:oldCacheDirectoryPath error:&error];
107 [songPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
108 NSString *oldPath = [oldCacheDirectoryPath stringByAppendingPathComponent:obj];
109- NSString *songId = [(NSString*)obj lastPathComponent];
110+ NSString *songId = [obj lastPathComponent];
111 Song *song = [Song songWithId:songId];
112 NSString *songIdPath = [song idPath];
113 NSError *error = nil;
114 [cacheFileManager cacheURL:[NSURL fileURLWithPath:oldPath] forFileId:songIdPath offline:YES error:&error];
115 }];
116
117- [fileManager removeItemAtPath:[CachedMusicDirectory() path] error:&error];
118+ [fileManager removeItemAtPath:oldCacheDirectoryPath error:&error];
119+
120+
121+ NSString *oldAlbumArtCachePath = [[ApplicationDocumentsDirectory() URLByAppendingPathComponent:@"cached_album_art"] path];
122+ if ([fileManager fileExistsAtPath:oldAlbumArtCachePath])
123+ {
124+ [fileManager moveItemAtPath:oldAlbumArtCachePath toPath:[CachedAlbumArtDirectory() path] error:NULL];
125+ }
126 }
127
128 #pragma mark - View lifecycle

Subscribers

People subscribed via source and target branches