Files
xtool/Sources/XUtils/XToolCache.swift
2026-10-28 18:15:02 -04:00

23 lines
790 B
Swift

import Foundation
package enum XToolCache {
package static var directory: URL {
let env = ProcessInfo.processInfo.environment
if let tmpdir = env["XTL_TMPDIR"], !tmpdir.isEmpty {
return URL(fileURLWithPath: tmpdir).appendingPathComponent("sh.xtool")
}
#if os(Linux)
let xdgCache: URL
if let xdgCachePath = env["XDG_CACHE_HOME"],
(xdgCachePath as NSString).isAbsolutePath {
xdgCache = URL(filePath: xdgCachePath)
} else {
xdgCache = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".cache")
}
return xdgCache.appending(component: "xtool")
#else
return URL.cachesDirectory.appending(component: "sh.xtool")
#endif
}
}