mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 11:20:18 +00:00
Improve storage usage report
This commit is contained in:
parent
56a6df1b72
commit
c995b73feb
@ -157,12 +157,35 @@ private func statForDirectory(path: String) -> Int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func collectDirectoryUsageReportRecursive(path: String, indent: String, log: inout String) {
|
||||||
|
guard let enumerator = FileManager.default.enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: [.isDirectoryKey, .fileAllocatedSizeKey, .isSymbolicLinkKey], options: .skipsSubdirectoryDescendants) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for url in enumerator {
|
||||||
|
guard let url = url as? URL else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if let isDirectoryValue = (try? url.resourceValues(forKeys: Set([.isDirectoryKey])))?.isDirectory, isDirectoryValue {
|
||||||
|
let subdirectorySize = statForDirectory(path: url.path)
|
||||||
|
log.append("\(indent)+ \(url.lastPathComponent): \(subdirectorySize)\n")
|
||||||
|
collectDirectoryUsageReportRecursive(path: url.path, indent: indent + " ", log: &log)
|
||||||
|
} else if let fileSizeValue = (try? url.resourceValues(forKeys: Set([.fileAllocatedSizeKey])))?.fileAllocatedSize {
|
||||||
|
if let isSymbolicLinkValue = (try? url.resourceValues(forKeys: Set([.isSymbolicLinkKey])))?.isSymbolicLink, isSymbolicLinkValue {
|
||||||
|
log.append("\(indent)\(url.lastPathComponent): SYMLINK\n")
|
||||||
|
} else {
|
||||||
|
log.append("\(indent)\(url.lastPathComponent): \(fileSizeValue)\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func collectRawStorageUsageReport(containerPath: String) -> String {
|
public func collectRawStorageUsageReport(containerPath: String) -> String {
|
||||||
var log = ""
|
var log = ""
|
||||||
|
|
||||||
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
||||||
let documentsSize = statForDirectory(path: documentsPath)
|
let documentsSize = statForDirectory(path: documentsPath)
|
||||||
log.append("Documents (\(documentsPath)): \(documentsSize)\n")
|
log.append("Documents (\(documentsPath)): \(documentsSize)\n")
|
||||||
|
collectDirectoryUsageReportRecursive(path: documentsPath, indent: " ", log: &log)
|
||||||
|
|
||||||
let systemCachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
|
let systemCachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
|
||||||
let systemCacheSize = statForDirectory(path: systemCachePath)
|
let systemCacheSize = statForDirectory(path: systemCachePath)
|
||||||
@ -170,6 +193,7 @@ public func collectRawStorageUsageReport(containerPath: String) -> String {
|
|||||||
|
|
||||||
let containerSize = statForDirectory(path: containerPath)
|
let containerSize = statForDirectory(path: containerPath)
|
||||||
log.append("Container (\(containerPath)): \(containerSize)\n")
|
log.append("Container (\(containerPath)): \(containerSize)\n")
|
||||||
|
collectDirectoryUsageReportRecursive(path: containerPath, indent: " ", log: &log)
|
||||||
|
|
||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user