1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2020 Google LLC
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORStorageProtocol.h"
|
|
|
20 |
|
|
|
21 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
22 |
|
|
|
23 |
/** The class calculates and caches the specified directory content size and uses add/remove signals
|
|
|
24 |
* from client the client to keep the size up to date without accessing file system.
|
|
|
25 |
* This is an internal class designed to be used by `GDTCORFlatFileStorage`.
|
|
|
26 |
* NOTE: The class is not thread-safe. The client must take care of synchronization.
|
|
|
27 |
*/
|
|
|
28 |
@interface GDTCORDirectorySizeTracker : NSObject
|
|
|
29 |
|
|
|
30 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
31 |
|
|
|
32 |
/** Initializes the object with a directory path.
|
|
|
33 |
* @param path The directory path to track content size.
|
|
|
34 |
*/
|
|
|
35 |
- (instancetype)initWithDirectoryPath:(NSString *)path;
|
|
|
36 |
|
|
|
37 |
/** Returns a cached or calculates (if there is no cached) directory content size.
|
|
|
38 |
* @return The directory content size in bytes calculated based on `NSURLFileSizeKey`.
|
|
|
39 |
*/
|
|
|
40 |
- (GDTCORStorageSizeBytes)directoryContentSize;
|
|
|
41 |
|
|
|
42 |
/** The client must call this method or `resetCachedSize` method each time a file or directory is
|
|
|
43 |
* added to the tracked directory.
|
|
|
44 |
* @param path The path to the added file. If the path is outside the tracked directory then the
|
|
|
45 |
* @param fileSize The size of the added file.
|
|
|
46 |
* method is no-op.
|
|
|
47 |
*/
|
|
|
48 |
- (void)fileWasAddedAtPath:(NSString *)path withSize:(GDTCORStorageSizeBytes)fileSize;
|
|
|
49 |
|
|
|
50 |
/** The client must call this method or `resetCachedSize` method each time a file or directory is
|
|
|
51 |
* removed from the tracked directory.
|
|
|
52 |
* @param path The path to the removed file. If the path is outside the tracked directory then the
|
|
|
53 |
* @param fileSize The size of the removed file.
|
|
|
54 |
* method is no-op.
|
|
|
55 |
*/
|
|
|
56 |
- (void)fileWasRemovedAtPath:(NSString *)path withSize:(GDTCORStorageSizeBytes)fileSize;
|
|
|
57 |
|
|
|
58 |
/** Invalidates cached directory size. */
|
|
|
59 |
- (void)resetCachedSize;
|
|
|
60 |
|
|
|
61 |
/** Returns URL resource value for `NSURLFileSizeKey` key for the specified URL. */
|
|
|
62 |
- (GDTCORStorageSizeBytes)fileSizeAtURL:(NSURL *)fileURL;
|
|
|
63 |
|
|
|
64 |
@end
|
|
|
65 |
|
|
|
66 |
NS_ASSUME_NONNULL_END
|