Files
purchases-ios/Sources/Logging/Strings/CacheStrings.swift
T
Antonio Pallares c9575c5165 Fix "Failed to create cache directory" error log on tvOS (#6487)
* Make DirectoryType.applicationSupport unavailable on tvOS

tvOS sandbox only allows writes under Library/Caches on physical
devices — attempts to create directories under Library/Application
Support fail with NSCocoaErrorDomain 513 / EPERM. Mark the
.applicationSupport case as @available(tvOS, unavailable) so callers
get a compile-time error, and fall back to .cache at each call site.

Made-with: Cursor

* Guard test code referencing .applicationSupport from tvOS

Wrap DiagnosticsFileOldFileDeletionTests and the .applicationSupport
switch arm in MockLargeItemCache with #if !os(tvOS) to match the
@available(tvOS, unavailable) annotation on the enum case.

Made-with: Cursor

* Log warning for ignored applicationSupportDirectory on tvOS, add directory type test

- Warn at init when applicationSupportDirectory override is passed on
  tvOS, since it is silently ignored in favour of .cache.
- Add testInitUsesCacheDirectoryOnTvOS verifying the correct directory
  type is selected per platform.

Made-with: Cursor

* Adapt DiagnosticsFileOldFileDeletionTests to run on tvOS

Instead of disabling the entire test class on tvOS, use a
persistenceDirectoryType helper that selects .cache on tvOS
and .applicationSupport() elsewhere, so the migration tests
verify the correct destination directory per platform.

Made-with: Cursor
2026-03-20 10:50:44 +00:00

46 lines
1.5 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// CacheStrings.swift
//
// Created by Rick van der Linden on 12/01/2026.
import Foundation
// swiftlint:disable identifier_name
enum CacheStrings {
case cache_url_not_available
case failed_to_save_codable_to_cache(Error)
case failed_to_delete_old_cache_directory(Error)
case failed_to_migrate_file(String, Error)
case application_support_not_available_on_tvos
}
extension CacheStrings: LogMessage {
var description: String {
switch self {
case .cache_url_not_available:
return "Cache URL is not available"
case .failed_to_save_codable_to_cache(let error):
return "Failed to save codable to cache: \(error)"
case .failed_to_delete_old_cache_directory(let error):
return "Failed to delete old cache directory: \(error)"
case .failed_to_migrate_file(let path, let error):
return "Failed to migrate file from \(path): \(error)"
case .application_support_not_available_on_tvos:
return "applicationSupportDirectory override ignored: " +
"Application Support is not writable on tvOS, using Caches directory instead."
}
}
var category: String { return "cache" }
}