fix: changed the order of disk capacity reader because of tons of logs on m1

This commit is contained in:
Serhiy Mytrovtsiy
2022-11-12 11:30:00 +01:00
parent 87fa8e0c5c
commit 9948f6ea6f

View File

@@ -70,6 +70,15 @@ internal class CapacityReader: Reader<Disks> {
}
private func freeDiskSpaceInBytes(_ path: URL) -> Int64 {
do {
let systemAttributes = try FileManager.default.attributesOfFileSystem(forPath: path.path)
if let freeSpace = (systemAttributes[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value {
return freeSpace
}
} catch let err {
error("error retrieving free space #2: \(err.localizedDescription)", log: self.log)
}
do {
if let url = URL(string: path.absoluteString) {
let values = try url.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
@@ -81,15 +90,6 @@ internal class CapacityReader: Reader<Disks> {
error("error retrieving free space #1: \(err.localizedDescription)", log: self.log)
}
do {
let systemAttributes = try FileManager.default.attributesOfFileSystem(forPath: path.path)
if let freeSpace = (systemAttributes[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value {
return freeSpace
}
} catch let err {
error("error retrieving free space #2: \(err.localizedDescription)", log: self.log)
}
return 0
}
}