mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Check tmp dir size
This commit is contained in:
parent
524e8f1e81
commit
b92a46ee58
@ -25,6 +25,7 @@ swift_library(
|
||||
"//submodules/GZip:GZip",
|
||||
"//third-party/ZipArchive:ZipArchive",
|
||||
"//submodules/InAppPurchaseManager:InAppPurchaseManager",
|
||||
"//submodules/Utils/DarwinDirStat",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -16,6 +16,7 @@ import AppBundle
|
||||
import ZipArchive
|
||||
import WebKit
|
||||
import InAppPurchaseManager
|
||||
import DarwinDirStat
|
||||
|
||||
@objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate {
|
||||
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
||||
@ -947,10 +948,15 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
||||
case .resetTranslationStates:
|
||||
return ItemListActionItem(presentationData: presentationData, title: "Reset Translation States", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
||||
if let context = arguments.context {
|
||||
let _ = context.engine.itemCache.clear(collectionIds: [
|
||||
ApplicationSpecificItemCacheCollectionId.translationState
|
||||
]).start()
|
||||
let size = statForDirectory(path: NSTemporaryDirectory())
|
||||
let controller = textAlertController(context: context, title: nil, text: "temp dir size \(size)", actions: [TextAlertAction(type: .genericAction, title: "OK", action: {})])
|
||||
arguments.presentController(controller, nil)
|
||||
}
|
||||
// if let context = arguments.context {
|
||||
// let _ = context.engine.itemCache.clear(collectionIds: [
|
||||
// ApplicationSpecificItemCacheCollectionId.translationState
|
||||
// ]).start()
|
||||
// }
|
||||
})
|
||||
case .crash:
|
||||
return ItemListActionItem(presentationData: presentationData, title: "Crash", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
||||
@ -1539,3 +1545,30 @@ public func triggerDebugSendLogsUI(context: AccountContext, additionalInfo: Stri
|
||||
pushController(controller)
|
||||
})
|
||||
}
|
||||
|
||||
private func statForDirectory(path: String) -> Int64 {
|
||||
if #available(macOS 10.13, *) {
|
||||
var s = darwin_dirstat()
|
||||
var result = dirstat_np(path, 1, &s, MemoryLayout<darwin_dirstat>.size)
|
||||
if result != -1 {
|
||||
return Int64(s.total_size)
|
||||
} else {
|
||||
result = dirstat_np(path, 0, &s, MemoryLayout<darwin_dirstat>.size)
|
||||
if result != -1 {
|
||||
return Int64(s.total_size)
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let fileManager = FileManager.default
|
||||
let folderURL = URL(fileURLWithPath: path)
|
||||
var folderSize: Int64 = 0
|
||||
if let files = try? fileManager.contentsOfDirectory(at: folderURL, includingPropertiesForKeys: nil, options: []) {
|
||||
for file in files {
|
||||
folderSize += (fileSize(file.path) ?? 0)
|
||||
}
|
||||
}
|
||||
return folderSize
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user