From b52e4f574021a96eb76474e6e9eecd4abac649e0 Mon Sep 17 00:00:00 2001 From: christophhagen Date: Thu, 28 May 2020 14:34:07 +0200 Subject: [PATCH] Add more logging --- Sources/App/routes.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index 3711aa6..9282757 100755 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -91,11 +91,13 @@ public func routes(_ router: Router) throws { if !fm.fileExists(atPath: url.path) { try fm.createDirectory(at: url, withIntermediateDirectories: false) } + log("Added cap \(cap)") } else { caps[index] = name + log("Set name for cap \(cap)") } try caps.joined(separator: "\n").data(using: .utf8)!.write(to: nameFile) - log("Set name for cap \(cap) (\(caps.count) caps loaded)") + } // Upload an image @@ -107,6 +109,7 @@ public func routes(_ router: Router) throws { let c = try count(of: cap) let f = file(of: cap, version: c) guard !fm.fileExists(atPath: f.path) else { + log("Image \(c) for cap \(cap) already exists on disk") throw CapError.dataInconsistency } try data.write(to: f) @@ -130,18 +133,22 @@ public func routes(_ router: Router) throws { let cap = try request.parameters.next(Int.self) let version = try request.parameters.next(Int.self) guard version > 0 else { + log("Not switching cap \(cap) to image \(version)") return } let file1 = file(of: cap, version: 0) guard fm.fileExists(atPath: file1.path) else { + log("No image 0 for cap \(cap)") throw CapError.invalidFile } let file2 = file(of: cap, version: version) guard fm.fileExists(atPath: file2.path) else { + log("No image \(version) for cap \(cap)") throw CapError.invalidFile } try fm.moveItem(at: file1, to: tempImageFile) try fm.moveItem(at: file2, to: file1) try fm.moveItem(at: tempImageFile, to: file2) + log("Switched cap \(cap) to version \(version)") } }