Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

fix(linux): use home cache dir to avoid tmpfs→ext4 EINVAL on SDK install (#211)

Swapnil Nakatec65d45ba6067
diff --git a/Sources/XUtils/TemporaryDirectory.swift b/Sources/XUtils/TemporaryDirectory.swift
index 6f50a30..d3206c8 100644
--- a/Sources/XUtils/TemporaryDirectory.swift
+++ b/Sources/XUtils/TemporaryDirectory.swift
@@ -65,15 +65,24 @@ private struct TemporaryDirectoryRoot {
}
private init() {
- let base: URL
+ let url: URL
let env = ProcessInfo.processInfo.environment
if let tmpdir = env["XTL_TMPDIR"] ?? env["TMPDIR"] {
- base = URL(fileURLWithPath: tmpdir)
+ url = URL(fileURLWithPath: tmpdir).appendingPathComponent("sh.xtool")
} else {
- base = FileManager.default.temporaryDirectory
+ #if os(Linux)
+ // On Linux, /tmp is commonly a tmpfs mount while ~/.swiftpm lives on ext4.
+ // Foundation's FileManager.copyItem uses sendfile(2) internally, which returns
+ // EINVAL when copying between different filesystem types (e.g. tmpfs → ext4).
+ // This causes `swift sdk install` to fail on distros like Linux Mint (#181).
+ // Using a cache dir on the home filesystem avoids the cross-fs copy entirely.
+ let xdgCache = env["XDG_CACHE_HOME"].map { URL(fileURLWithPath: $0) }
+ ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".cache")
+ url = xdgCache.appendingPathComponent("xtool")
+ #else
+ url = FileManager.default.temporaryDirectory.appendingPathComponent("sh.xtool")
+ #endif
}
-
- let url = base.appendingPathComponent("sh.xtool")
try? FileManager.default.removeItem(at: url)
do {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)