mirror of
https://github.com/munki/munki.git
synced 2026-05-02 02:09:19 -05:00
Move filesize functions to fileutils
This commit is contained in:
@@ -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 = ""
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user