Skip to content

Commit 11ab4a5

Browse files
committed
Add reserve option
1 parent 252ce9f commit 11ab4a5

File tree

3 files changed

+121
-155
lines changed

3 files changed

+121
-155
lines changed

LSDocument.m

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,69 +27,6 @@ - (void)saveWithCompletionHandler:(void (^)(BOOL success))completionHandler
2727
[self saveToURL:self.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:completionHandler];
2828
}
2929

30-
- (BOOL)writePathFirst:(LSFileWrapper *)file
31-
andAttributes:(NSDictionary *)additionalFileAttributes
32-
safelyToURL:(NSURL *)url
33-
forSaveOperation:(UIDocumentSaveOperation)saveOperation
34-
error:(NSError *__autoreleasing *)outError
35-
{
36-
return [file writeUpdatesToURL:url error:outError];
37-
}
38-
39-
- (void)savePathFirst:(NSString *)path
40-
firstHandler:(void (^)(BOOL success))firstHandler
41-
completionHandler:(void (^)(BOOL success))completionHandler
42-
{
43-
NSError *contentError;
44-
NSURL *url = [self.fileURL copy];
45-
LSFileWrapper *contents = [self contentsForType:self.fileType error:&contentError];
46-
if(!contents) {
47-
return;
48-
}
49-
50-
LSFileWrapper *file = [contents fileWrapperWithPath:path];
51-
NSURL *firstURL = [url URLByAppendingPathComponent:path];
52-
53-
[self performAsynchronousFileAccessUsingBlock:^{
54-
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:self];
55-
56-
[fileCoordinator coordinateWritingItemAtURL:url
57-
options:NSFileCoordinatorWritingForMerging
58-
error:nil
59-
byAccessor:
60-
^(NSURL *newURL) {
61-
NSError *writeError;
62-
BOOL wroteFirst, wroteAll;
63-
64-
wroteFirst = [self writePathFirst:file
65-
andAttributes:nil
66-
safelyToURL:firstURL
67-
forSaveOperation:UIDocumentSaveForOverwriting
68-
error:&writeError];
69-
70-
if(firstHandler) {
71-
dispatch_async(dispatch_get_main_queue(), ^(void) {
72-
firstHandler(wroteFirst);
73-
});
74-
}
75-
76-
if(wroteFirst) {
77-
wroteAll = [self writeContents:contents
78-
andAttributes:nil
79-
safelyToURL:url
80-
forSaveOperation:UIDocumentSaveForOverwriting
81-
error:&writeError];
82-
}
83-
84-
if(completionHandler) {
85-
dispatch_async(dispatch_get_main_queue(), ^(void) {
86-
completionHandler(wroteAll);
87-
});
88-
}
89-
}];
90-
}];
91-
}
92-
9330
- (BOOL)readFromURL:(NSURL *)url error:(NSError *__autoreleasing *)outError
9431
{
9532
__block LSFileWrapper *wrapper = [[LSFileWrapper alloc] initWithURL:url isDirectory:NO];
@@ -99,7 +36,6 @@ - (BOOL)readFromURL:(NSURL *)url error:(NSError *__autoreleasing *)outError
9936
ofType:self.fileType
10037
error:outError];
10138
});
102-
[wrapper loadCache];
10339
return result;
10440
}
10541

LSFileWrapper.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
- (id)initDirectory;
1414
- (id)initWithURL:(NSURL *)url isDirectory:(BOOL)isDir;
1515

16-
- (void)loadCache;
17-
1816
- (NSData *)data;
1917
- (NSString *)string;
2018
- (NSDictionary *)dictionary;
@@ -23,6 +21,10 @@
2321
- (void)updateContent:(id<NSObject>)content;
2422
- (void)deleteContent;
2523

24+
- (void)incReserve;
25+
- (void)decReserve;
26+
- (void)deleteUnreserved;
27+
2628
- (LSFileWrapper *)fileWrapperWithPath:(NSString *)path;
2729
- (LSFileWrapper *)fileWrapperWithPath:(NSString *)path create:(BOOL)create isDirectory:(BOOL)isDir;
2830

@@ -37,5 +39,5 @@
3739
@property (readonly, strong, nonatomic) NSString *fileType;
3840
@property (readonly, nonatomic) BOOL updated;
3941
@property (readonly, nonatomic) BOOL isDirectory;
40-
@property (assign, nonatomic) BOOL cacheFile;
42+
@property (assign, nonatomic) NSInteger reserve;
4143
@end

0 commit comments

Comments
 (0)