GDTCORDirectorySizeTracker.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #import <Foundation/Foundation.h>
  17. #import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCORStorageProtocol.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** The class calculates and caches the specified directory content size and uses add/remove signals
  20. * from client the client to keep the size up to date without accessing file system.
  21. * This is an internal class designed to be used by `GDTCORFlatFileStorage`.
  22. * NOTE: The class is not thread-safe. The client must take care of synchronization.
  23. */
  24. @interface GDTCORDirectorySizeTracker : NSObject
  25. - (instancetype)init NS_UNAVAILABLE;
  26. /** Initializes the object with a directory path.
  27. * @param path The directory path to track content size.
  28. */
  29. - (instancetype)initWithDirectoryPath:(NSString *)path;
  30. /** Returns a cached or calculates (if there is no cached) directory content size.
  31. * @return The directory content size in bytes calculated based on `NSURLFileSizeKey`.
  32. */
  33. - (GDTCORStorageSizeBytes)directoryContentSize;
  34. /** The client must call this method or `resetCachedSize` method each time a file or directory is
  35. * added to the tracked directory.
  36. * @param path The path to the added file. If the path is outside the tracked directory then the
  37. * @param fileSize The size of the added file.
  38. * method is no-op.
  39. */
  40. - (void)fileWasAddedAtPath:(NSString *)path withSize:(GDTCORStorageSizeBytes)fileSize;
  41. /** The client must call this method or `resetCachedSize` method each time a file or directory is
  42. * removed from the tracked directory.
  43. * @param path The path to the removed file. If the path is outside the tracked directory then the
  44. * @param fileSize The size of the removed file.
  45. * method is no-op.
  46. */
  47. - (void)fileWasRemovedAtPath:(NSString *)path withSize:(GDTCORStorageSizeBytes)fileSize;
  48. /** Invalidates cached directory size. */
  49. - (void)resetCachedSize;
  50. /** Returns URL resource value for `NSURLFileSizeKey` key for the specified URL. */
  51. - (GDTCORStorageSizeBytes)fileSizeAtURL:(NSURL *)fileURL;
  52. @end
  53. NS_ASSUME_NONNULL_END