mirror of
https://github.com/trycua/computer.git
synced 2026-05-09 08:49:33 -05:00
Add support for ephemeral storage
This commit is contained in:
@@ -72,6 +72,22 @@ final class Home {
|
||||
/// - Returns: A VMDirectory instance
|
||||
/// - Throws: HomeError if location not found
|
||||
func getVMDirectory(_ name: String, storage: String? = nil) throws -> VMDirectory {
|
||||
// Special case for ephemeral storage using macOS temporary directory
|
||||
if let storage = storage, storage == "ephemeral" {
|
||||
// Get the current temporary directory
|
||||
let tmpDir = ProcessInfo.processInfo.environment["TMPDIR"] ?? "/tmp"
|
||||
// Remove trailing slash if present
|
||||
let cleanPath = tmpDir.hasSuffix("/") ? String(tmpDir.dropLast()) : tmpDir
|
||||
|
||||
// Create the directory if it doesn't exist
|
||||
if !fileExists(at: cleanPath) {
|
||||
try createVMLocation(at: cleanPath)
|
||||
}
|
||||
|
||||
let baseDir = Path(cleanPath)
|
||||
return VMDirectory(baseDir.directory(name))
|
||||
}
|
||||
|
||||
let location: VMLocation
|
||||
|
||||
if let storage = storage {
|
||||
@@ -123,6 +139,55 @@ final class Home {
|
||||
|
||||
// Loop through all locations
|
||||
let settings = settingsManager.getSettings()
|
||||
|
||||
// Also check ephemeral directory (macOS temporary directory)
|
||||
let tmpDir = ProcessInfo.processInfo.environment["TMPDIR"] ?? "/tmp"
|
||||
let cleanPath = tmpDir.hasSuffix("/") ? String(tmpDir.dropLast()) : tmpDir
|
||||
|
||||
// If tmp directory exists, check for VMs there
|
||||
if fileExists(at: cleanPath) {
|
||||
let tmpDirPath = Path(cleanPath)
|
||||
do {
|
||||
let directoryURL = URL(fileURLWithPath: cleanPath)
|
||||
let contents = try FileManager.default.contentsOfDirectory(
|
||||
at: directoryURL,
|
||||
includingPropertiesForKeys: [.isDirectoryKey],
|
||||
options: .skipsHiddenFiles
|
||||
)
|
||||
|
||||
for subdir in contents {
|
||||
do {
|
||||
guard let isDirectory = try subdir.resourceValues(forKeys: [.isDirectoryKey]).isDirectory,
|
||||
isDirectory else {
|
||||
continue
|
||||
}
|
||||
|
||||
let vmName = subdir.lastPathComponent
|
||||
let vmDir = VMDirectory(tmpDirPath.directory(vmName))
|
||||
|
||||
// Only include if it's a valid VM directory
|
||||
if vmDir.initialized() {
|
||||
results.append(VMDirectoryWithLocation(
|
||||
directory: vmDir,
|
||||
locationName: "ephemeral"
|
||||
))
|
||||
}
|
||||
} catch {
|
||||
// Skip any directories we can't access
|
||||
continue
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Logger.error(
|
||||
"Failed to access ephemeral directory",
|
||||
metadata: [
|
||||
"path": cleanPath,
|
||||
"error": error.localizedDescription,
|
||||
]
|
||||
)
|
||||
// Continue to regular locations rather than failing completely
|
||||
}
|
||||
}
|
||||
for location in settings.vmLocations {
|
||||
let locationPath = Path(location.expandedPath)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user