mirror of
				https://github.com/GayPizzaSpecifications/darwin-apk.git
				synced 2025-11-04 07:59:38 +00:00 
			
		
		
		
	Don't know if I'm a fan, but async'ing RepositoriesConfig is simpler
This commit is contained in:
		@ -11,25 +11,16 @@ struct RepositoriesConfig {
 | 
				
			|||||||
  let repositories: [ApkIndexRepository]
 | 
					  let repositories: [ApkIndexRepository]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  init() async throws(ExitCode) {
 | 
					  init() async throws(ExitCode) {
 | 
				
			||||||
    let repositories: [String], architectures: [String]
 | 
					 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
      repositories = try await Self.read(name: "repositories")
 | 
					      self.repositories = try await Self.readConfig(name: "repositories").flatMap { repo in
 | 
				
			||||||
 | 
					        Self.readConfig(name: "arch").map { arch in
 | 
				
			||||||
 | 
					          ApkIndexRepository(name: repo, arch: arch)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }.reduce(into: []) { $0.append($1) }
 | 
				
			||||||
    } catch {
 | 
					    } catch {
 | 
				
			||||||
      print("Failed to read repositories: \(error.localizedDescription)")
 | 
					      print("Failed to read repository configurations, \(error.localizedDescription)")
 | 
				
			||||||
      throw .failure
 | 
					      throw .failure
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    do {
 | 
					 | 
				
			||||||
      architectures = try await Self.read(name: "arch")
 | 
					 | 
				
			||||||
    } catch {
 | 
					 | 
				
			||||||
      print("Failed to read arch: \(error.localizedDescription)")
 | 
					 | 
				
			||||||
      throw .failure
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    self.repositories = repositories.flatMap { repo in
 | 
					 | 
				
			||||||
      architectures.map { arch in
 | 
					 | 
				
			||||||
        ApkIndexRepository(name: repo, arch: arch)
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var localRepositories: [URL] {
 | 
					  var localRepositories: [URL] {
 | 
				
			||||||
@ -38,10 +29,10 @@ struct RepositoriesConfig {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static func read(name: String) async throws -> [String] {
 | 
					  private static func readConfig(name: String)
 | 
				
			||||||
    try await URL(filePath: name, directoryHint: .notDirectory).lines
 | 
					      -> AsyncFilterSequence<AsyncMapSequence<AsyncLineSequence<URL.AsyncBytes>, String>> {
 | 
				
			||||||
 | 
					    return URL(filePath: name, directoryHint: .notDirectory).lines
 | 
				
			||||||
      .map { $0.trimmingCharacters(in: .whitespaces) }
 | 
					      .map { $0.trimmingCharacters(in: .whitespaces) }
 | 
				
			||||||
      .filter { !$0.isEmpty && $0.first != "#" }  // Ignore empty & commented lines
 | 
					      .filter { !$0.isEmpty && $0.first != "#" }  // Ignore empty & commented lines
 | 
				
			||||||
      .reduce(into: [String]()) { $0.append($1) }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user