From 6d18c58f38930ef64478996a47c0c8061e4a8dc6 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 11 Jun 2022 01:01:24 +0200 Subject: [PATCH] Create folder for new caps --- Sources/App/CapServer.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/App/CapServer.swift b/Sources/App/CapServer.swift index 7532c0d..f583c33 100644 --- a/Sources/App/CapServer.swift +++ b/Sources/App/CapServer.swift @@ -170,10 +170,15 @@ final class CapServer { throw CapError.unknownId } var id = 0 + let capFolder = folder(of: cap) var f = file(of: cap, version: id) - while fm.fileExists(atPath: f.path) { - id += 1 - f = file(of: cap, version: id) + if fm.fileExists(atPath: capFolder.path) { + while fm.fileExists(atPath: f.path) { + id += 1 + f = file(of: cap, version: id) + } + } else { + try fm.createDirectory(at: capFolder, withIntermediateDirectories: true) } try data.write(to: f) caps[cap]!.count = try count(of: cap)