Run a virtual iPhone on an Apple Silicon Mac.
Swift
Leave sockets out of archives so a stopped machine exports
Lakra2e964ff0616
diff --git a/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift b/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swiftindex b0f56772..e25f8874 100644--- a/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift+++ b/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift@@ -187,6 +187,14 @@ public enum VPhoneArchiveWriter {}archive_read_disk_descend(disk)+ // No tar format stores a socket, and gnutar fails the whole+ // archive on one: a stopped machine's folder still holds the+ // `vphone.sock` its last run bound. A socket means nothing once+ // unpacked, so it is left out wherever it is.+ if mode_t(archive_entry_filetype(entry)) == S_IFSOCK {+ continue+ }+// Without a top-level name the root entry itself is skipped: an// archive of a directory's contents should not carry the directory.guard let stored = storedPath(relative, under: topLevel) else { continue }diff --git a/VPhoneKit/VPhoneArchiveKitTests/RoundTripTests.swift b/VPhoneKit/VPhoneArchiveKitTests/RoundTripTests.swiftindex 03525622..333025fc 100644--- a/VPhoneKit/VPhoneArchiveKitTests/RoundTripTests.swift+++ b/VPhoneKit/VPhoneArchiveKitTests/RoundTripTests.swift@@ -483,4 +483,47 @@ struct RoundTripTests {try Data(bytes).write(to: archive)}++ /// A stopped machine keeps the `vphone.sock` its last run bound, and+ /// gnutar refused the whole export on it. The socket is left out; the+ /// rest of the tree goes in.+ @Test+ func `a socket in the tree is left out of the archive`() throws {+ // Short: sun_path holds 104 bytes, more than the temporary+ // directory leaves for a UUID-named tree.+ let source = URL(fileURLWithPath: "/tmp/vrt-\(UUID().uuidString.prefix(8))", isDirectory: true)+ let archive = Self.scratch("sock").appendingPathExtension("tar")+ let destination = Self.scratch("sock-out")+ try FileManager.default.createDirectory(at: source, withIntermediateDirectories: true)+ try FileManager.default.createDirectory(at: destination, withIntermediateDirectories: true)+ defer {+ for url in [source, archive, destination] {+ try? FileManager.default.removeItem(at: url)+ }+ }+ try Data("config\n".utf8).write(to: source.appendingPathComponent("config.plist"))++ let socketPath = source.appendingPathComponent("vphone.sock").path+ let fd = socket(AF_UNIX, SOCK_STREAM, 0)+ #expect(fd >= 0)+ defer { close(fd) }+ var address = sockaddr_un()+ address.sun_family = sa_family_t(AF_UNIX)+ withUnsafeMutableBytes(of: &address.sun_path) { buffer in+ buffer.copyBytes(from: socketPath.utf8.prefix(buffer.count - 1))+ }+ let bound = withUnsafePointer(to: &address) {+ $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {+ bind(fd, $0, socklen_t(MemoryLayout<sockaddr_un>.size))+ }+ }+ #expect(bound == 0)++ try VPhoneArchiveWriter.create(archive: archive, from: source, topLevel: "Mulberry", format: .gnutar)+ try VPhoneArchiveExtractor.extract(archive, into: destination, options: .intoHostDirectory)++ let unpacked = destination.appendingPathComponent("Mulberry")+ #expect(FileManager.default.fileExists(atPath: unpacked.appendingPathComponent("config.plist").path))+ #expect(!FileManager.default.fileExists(atPath: unpacked.appendingPathComponent("vphone.sock").path))+ }}