Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions xcode/Safari-Extension/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ func getRequiredCode(_ filename: String, _ resources: [String], _ fileType: Stri
if resourceUrlPath.hasSuffix(fileType) {
let resourceFilename = sanitize(resourceUrlString)
let fileURL = directory.appendingPathComponent(resourceFilename)
resourceUrls.insert(fileURL)
// insert url to resolve symlink into set
resourceUrls.insert(fileURL.resolvingSymlinksInPath())
// only attempt to get resource if it does not yet exist
if FileManager.default.fileExists(atPath: fileURL.path) {continue}
// get the remote file contents
Expand All @@ -870,14 +871,18 @@ func getRequiredCode(_ filename: String, _ resources: [String], _ fileType: Stri
}
// cleanup downloaded files that are no longer required
do {
var downloadedUrls = Set<URL>()
// get all downloaded resources url
let downloadedUrls = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: [])
let fileUrls = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: [])
// insert url to resolve symlink into set
for url in fileUrls { downloadedUrls.insert(url.resolvingSymlinksInPath()) }
// exclude currently required resources
let abandonedUrls = Set(downloadedUrls).subtracting(resourceUrls)
// loop through abandoned urls and attempt to remove it
for abandonFlieUrl in abandonedUrls {
for abandonFileUrl in abandonedUrls {
do {
try FileManager.default.removeItem(at: abandonFlieUrl)
try FileManager.default.removeItem(at: abandonFileUrl)
logText("cleanup abandoned resource: \(unsanitize(abandonFileUrl.lastPathComponent))")
} catch {
err("failed to remove abandoned resource in getRequiredCode \(error.localizedDescription)")
}
Expand Down