mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-10 21:10:08 +02:00
🐛 Fix unsafe usage of try for path handling
This commit is contained in:
@@ -14,14 +14,18 @@ class ValetDomainScanner: DomainScanner {
|
|||||||
|
|
||||||
func resolveSiteCount(paths: [String]) -> Int {
|
func resolveSiteCount(paths: [String]) -> Int {
|
||||||
return paths.map { path in
|
return paths.map { path in
|
||||||
|
do {
|
||||||
let entries = try! FileSystem
|
let entries = try FileSystem
|
||||||
.getShallowContentsOfDirectory(path)
|
.getShallowContentsOfDirectory(path)
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
.map { self.isSite($0, forPath: path) }
|
.map { self.isSite($0, forPath: path) }
|
||||||
.filter { $0 == true}
|
.filter { $0 == true}
|
||||||
.count
|
.count
|
||||||
|
} catch {
|
||||||
|
Log.err("Unexpected error getting contents of \(path): \(error).")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
}.reduce(0, +)
|
}.reduce(0, +)
|
||||||
}
|
}
|
||||||
@@ -30,7 +34,8 @@ class ValetDomainScanner: DomainScanner {
|
|||||||
var sites: [ValetSite] = []
|
var sites: [ValetSite] = []
|
||||||
|
|
||||||
paths.forEach { path in
|
paths.forEach { path in
|
||||||
let entries = try! FileSystem
|
do {
|
||||||
|
let entries = try FileSystem
|
||||||
.getShallowContentsOfDirectory(path)
|
.getShallowContentsOfDirectory(path)
|
||||||
|
|
||||||
return entries.forEach {
|
return entries.forEach {
|
||||||
@@ -38,6 +43,9 @@ class ValetDomainScanner: DomainScanner {
|
|||||||
sites.append(site)
|
sites.append(site)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
Log.err("Unexpected error getting contents of \(path): \(error).")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sites
|
return sites
|
||||||
|
Reference in New Issue
Block a user