From 03af8a850cfce9699e8394e93fbf560c38e8bdfc Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Tue, 15 Oct 2024 20:34:05 +0400 Subject: [PATCH] Try lstat --- submodules/Postbox/Sources/FileSize.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/submodules/Postbox/Sources/FileSize.swift b/submodules/Postbox/Sources/FileSize.swift index 421036c1f8..ef4fc4863a 100644 --- a/submodules/Postbox/Sources/FileSize.swift +++ b/submodules/Postbox/Sources/FileSize.swift @@ -1,7 +1,7 @@ import Foundation public func fileSize(_ path: String, useTotalFileAllocatedSize: Bool = false) -> Int64? { - if useTotalFileAllocatedSize { + /*if useTotalFileAllocatedSize { let url = URL(fileURLWithPath: path) if let values = (try? url.resourceValues(forKeys: Set([.isRegularFileKey, .fileAllocatedSizeKey]))) { if values.isRegularFile ?? false { @@ -10,10 +10,18 @@ public func fileSize(_ path: String, useTotalFileAllocatedSize: Bool = false) -> } } } - } + }*/ var value = stat() - if stat(path, &value) == 0 { + if lstat(path, &value) == 0 { + if (value.st_mode & S_IFMT) == S_IFLNK { + return 0 + } + + if useTotalFileAllocatedSize { + return Int64(value.st_blocks) * Int64(value.st_blksize) + } + return value.st_size } else { return nil