Move filesize functions to fileutils

This commit is contained in:
Greg Neagle
2024-10-25 14:42:50 -07:00
parent 284ddc135c
commit b8377db09b
2 changed files with 20 additions and 14 deletions
-13
View File
@@ -145,19 +145,6 @@ func validateSourceAndDestination(mountpoint: String, item: PlistDict) -> (Bool,
return (true, sourceItemPath, fullDestinationPath)
}
/// Recursively gets size of pathname in bytes
func getSize(_ path: String) -> Int {
if pathIsDirectory(path) {
return getSizeOfDirectory(path)
}
if pathIsRegularFile(path) {
if let attributes = try? FileManager.default.attributesOfItem(atPath: path) {
return Int((attributes as NSDictionary).fileSize())
}
}
return 0
}
/// Subclass of AsyncProcessRunner that handles the progress output from /usr/bin/ditto
class DittoRunner: AsyncProcessRunner {
var remainingErrorOutput = ""
+20 -1
View File
@@ -131,7 +131,15 @@ func pathIsExecutableFile(_ path: String) -> Bool {
return false
}
/// Returns size of directory in Kbytes by recursively adding
/// Returns size of file in bytes
func getSizeOfFile(_ path: String) -> Int {
if let attributes = try? FileManager.default.attributesOfItem(atPath: path) {
return Int((attributes as NSDictionary).fileSize())
}
return 0
}
/// Returns size of directory in bytes by recursively adding
/// up the size of all files within
func getSizeOfDirectory(_ path: String) -> Int {
var totalSize = 0
@@ -149,6 +157,17 @@ func getSizeOfDirectory(_ path: String) -> Int {
return totalSize
}
/// Recursively gets size of pathname in bytes
func getSize(_ path: String) -> Int {
if pathIsDirectory(path) {
return getSizeOfDirectory(path)
}
if pathIsRegularFile(path) {
return getSizeOfFile(path)
}
return 0
}
// Returns absolute path to item referred to by path
func getAbsolutePath(_ path: String) -> String {
if (path as NSString).isAbsolutePath {