Skip to content

Commit

Permalink
Clean up Linting Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiede committed Dec 22, 2021
1 parent cc6121f commit 86ac154
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Sources/Bedrockifier/Commands/BackupCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class BackupCommand: Command {

@Option(name: "minKeep", short: "m", help: "Minimum count of backups to keep for a single world (default = 1)")
var minKeep: Int?

public init() {}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bedrockifier/Commands/BackupJobCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final class BackupJobCommand: Command {
containerName: serverContainer,
worldsPath: worldsUrl)
}

if let ownershipConfig = config.ownership {
Library.log.info("Performing Ownership Fixup")
try WorldBackup.fixOwnership(at: backupUrl, config: ownershipConfig)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Bedrockifier/Foundation/ConsoleLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class ConsoleLogger: LogHandler {
let formatter = DateFormatter()
formatter.timeZone = TimeZone.current
formatter.calendar = Calendar.current
formatter.dateFormat = "HH:mm:ss.SSS";
formatter.dateFormat = "HH:mm:ss.SSS"
return formatter
}()

Expand Down Expand Up @@ -80,14 +80,14 @@ public final class ConsoleLogger: LogHandler {
private func formatMessage(_ message: Logger.Message, level: Logger.Level, file: String, line: UInt) -> String {
var components: [String] = []

if (ConsoleLogger.showDetails) {
if ConsoleLogger.showDetails {
let nowString = ConsoleLogger.timeFormatter.string(from: Date())
components.append("[\(nowString)][\(level.rawValue.padding(toLength: 8, withPad: " ", startingAt: 0))]")
}

components.append("\(message)")

if (ConsoleLogger.showFilePosition) {
if ConsoleLogger.showFilePosition {
let shortFileName = URL(fileURLWithPath: file).lastPathComponent
components.append("(\(shortFileName):\(line))")
}
Expand Down
8 changes: 3 additions & 5 deletions Sources/Bedrockifier/Foundation/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Platform {
#endif

enum PlatformError: Error {
case Errno(error: Int32)
case errno(error: Int32)
}

static func changeOwner(path: String, uid: UInt32?, gid: UInt32?) throws {
Expand All @@ -49,7 +49,7 @@ struct Platform {
try path.withCString({ cchars in
let result = chown(cchars, realUid, realGid)
guard result == 0 else {
throw PlatformError.Errno(error: errno)
throw PlatformError.errno(error: errno)
}
})
}
Expand All @@ -58,10 +58,8 @@ struct Platform {
try path.withCString({ cchars in
let result = chmod(cchars, Mode(permissions))
guard result == 0 else {
throw PlatformError.Errno(error: errno)
throw PlatformError.errno(error: errno)
}
})
}
}


12 changes: 0 additions & 12 deletions Sources/Bedrockifier/Foundation/ServiceTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,3 @@ public class ServiceTimer<IDType> {
self.handler?()
}
}


/*
public func schedulePrecise(forDate date: Date) {
self.schedule(wallDeadline: DispatchWallTime(date: date), leeway: .milliseconds(1))
}
public func schedulePrecise(forDate date: Date, repeating interval: DispatchTimeInterval) {
self.schedule(wallDeadline: DispatchWallTime(date: date), repeating: interval, leeway: .milliseconds(1))
}
*/
2 changes: 1 addition & 1 deletion Sources/Bedrockifier/Model/World.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extension World {
do {
let uidStr = owner != nil ? owner!.description : "nil"
let gidStr = group != nil ? group!.description : "nil"
let permsStr = permissions != nil ? String(format:"%o", permissions!) : "nil"
let permsStr = permissions != nil ? String(format: "%o", permissions!) : "nil"
Library.log.debug("Ownership Change: \(uidStr):\(gidStr) with perms \(permsStr) at \(path)")

// Apply directly to the core node (folder or mcworld package)
Expand Down
5 changes: 4 additions & 1 deletion Sources/Bedrockifier/Model/WorldBackup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ extension WorldBackup {
}
}

public static func makeBackup(backupUrl: URL, dockerPath: String, containerName: String, worldsPath: URL) async throws {
public static func makeBackup(backupUrl: URL,
dockerPath: String,
containerName: String,
worldsPath: URL) async throws {
let arguments: [String] = getPtyArguments(dockerPath: dockerPath, containerName: containerName)

// Attach To Container
Expand Down
29 changes: 17 additions & 12 deletions Sources/Service/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,9 @@ struct Server: ParsableCommand {
var trace = false

mutating func run() throws {
var intervalTimer: ServiceTimer<String>? = nil
var intervalTimer: ServiceTimer<String>?

// Update Logging Level
if trace {
ConsoleLogger.logLevelOverride = .trace
ConsoleLogger.showFilePosition = true
} else if debug {
ConsoleLogger.logLevelOverride = .debug
ConsoleLogger.showFilePosition = true
}
updateLoggingLevel()

Server.logger.info("Initializing Bedrockifier Daemon")

Expand Down Expand Up @@ -108,7 +101,9 @@ struct Server: ParsableCommand {
timer.schedule(startingAt: Date(), repeating: .seconds(Int(interval)))
timer.setHandler {
Task {
await Server.runBackup(config: config, backupUrl: URL(fileURLWithPath: backupPath), dockerPath: dockerPath)
await Server.runBackup(config: config,
backupUrl: URL(fileURLWithPath: backupPath),
dockerPath: dockerPath)
}
}

Expand All @@ -119,6 +114,16 @@ struct Server: ParsableCommand {
dispatchMain()
}

private func updateLoggingLevel() {
if trace {
ConsoleLogger.logLevelOverride = .trace
ConsoleLogger.showFilePosition = true
} else if debug {
ConsoleLogger.logLevelOverride = .debug
ConsoleLogger.showFilePosition = true
}
}

private static func runBackup(config: BackupConfig, backupUrl: URL, dockerPath: String) async {
Server.logger.info("Starting Backup")
do {
Expand All @@ -145,11 +150,11 @@ struct Server: ParsableCommand {
}

Server.logger.info("Backup Completed")
let _ = Server.markHealthy(backupUrl: backupUrl)
_ = Server.markHealthy(backupUrl: backupUrl)
} catch let error {
Server.logger.error("\(error.localizedDescription)")
Server.logger.error("Backup Failed")
let _ = Server.markUnhealthy(backupUrl: backupUrl)
_ = Server.markUnhealthy(backupUrl: backupUrl)
}
}

Expand Down
20 changes: 10 additions & 10 deletions Tests/BedrockifierTests/OwnershipStringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import XCTest
final class OwnershipStringTests: XCTestCase {
func testInvalidString() {
do {
let _ = try parse(ownership: "helloworld")
_ = try parse(ownership: "helloworld")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(ownership: "hello:world")
_ = try parse(ownership: "hello:world")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(ownership: "123:world")
_ = try parse(ownership: "123:world")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(ownership: "hello:456")
_ = try parse(ownership: "hello:456")
XCTFail("Expected string to throw")
} catch {
// Expected
Expand Down Expand Up @@ -82,21 +82,21 @@ final class OwnershipStringTests: XCTestCase {

func testInvalidPermissions() {
do {
let _ = try parse(permissions: "hello")
_ = try parse(permissions: "hello")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(permissions: "world")
_ = try parse(permissions: "world")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(permissions: "123:456")
_ = try parse(permissions: "123:456")
XCTFail("Expected string to throw")
} catch {
// Expected
Expand All @@ -105,21 +105,21 @@ final class OwnershipStringTests: XCTestCase {

func testOutOfBoundsPermissions() {
do {
let _ = try parse(permissions: "778")
_ = try parse(permissions: "778")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(permissions: "888")
_ = try parse(permissions: "888")
XCTFail("Expected string to throw")
} catch {
// Expected
}

do {
let _ = try parse(permissions: "1000")
_ = try parse(permissions: "1000")
XCTFail("Expected string to throw")
} catch {
// Expected
Expand Down

0 comments on commit 86ac154

Please sign in to comment.