Skip to content

Commit fbed9a5

Browse files
committed
feat: adds apfs and noexec
1 parent 99d1b79 commit fbed9a5

File tree

12 files changed

+556
-292
lines changed

12 files changed

+556
-292
lines changed

Common/FileSystemManager.swift

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// FileSystemManager.swift
3+
// TmpDisk
4+
//
5+
// Created by Tim on 4/3/25.
6+
//
7+
8+
import Foundation
9+
10+
struct FileSystemType: Identifiable, Hashable {
11+
let id = UUID()
12+
let name: String
13+
let description: String
14+
15+
func hash(into hasher: inout Hasher) {
16+
hasher.combine(name)
17+
}
18+
19+
static func == (lhs: FileSystemType, rhs: FileSystemType) -> Bool {
20+
return lhs.name == rhs.name
21+
}
22+
}
23+
24+
class FileSystemManager {
25+
// All filesystem types with descriptions
26+
private static let allFileSystems: [FileSystemType] = [
27+
FileSystemType(name: "APFS", description: "Apple File System - Suggested"),
28+
FileSystemType(name: "APFSX", description: "Apple File System (Case Sensitive)"),
29+
FileSystemType(name: "HFS+", description: "Mac OS Extended - Legacy"),
30+
FileSystemType(name: "TMPFS", description: "TmpFS - Requires Admin or TmpDisk Helper"),
31+
FileSystemType(name: "HFSX", description: "Mac OS Extended (Case-sensitive)"),
32+
FileSystemType(name: "JHFS+", description: "Mac OS Extended (Journaled)"),
33+
FileSystemType(name: "JHFSX", description: "Mac OS Extended (Case-sensitive, Journaled)"),
34+
]
35+
36+
// Get filesystem types appropriate for the current OS version
37+
static func availableFileSystems() -> [FileSystemType] {
38+
var available = allFileSystems
39+
40+
if #available(macOS 10.13, *) {
41+
// Keep APFS for macOS 10.13+ (High Sierra and later)
42+
} else {
43+
// Remove APFS from available options for earlier macOS versions
44+
available.removeAll { $0.name == "APFS" || $0.name == "APFSX" }
45+
}
46+
47+
return available
48+
}
49+
50+
// Get the descriptions of avaialable file systems
51+
static func availableFileSystemDescriptions() -> [String] {
52+
return availableFileSystems().map(\.self.description)
53+
}
54+
55+
static func isTmpFS(_ fileSystemName: String) -> Bool {
56+
return fileSystemName == "TMPFS"
57+
}
58+
59+
static func isAPFS(_ fileSystemName: String) -> Bool {
60+
return fileSystemName == "APFS" || fileSystemName == "APFSX"
61+
}
62+
63+
static func description(for fileSystemName: String) -> String? {
64+
return availableFileSystems().first(where: { $0.name == fileSystemName })?.description
65+
}
66+
}

Common/TmpDiskVolume.swift

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,73 @@ struct TmpDiskVolume: Hashable, Codable {
1111
var name: String = ""
1212
var size: Int = 16
1313
var autoCreate: Bool = false
14+
var fileSystem: String
1415
var indexed: Bool = false
16+
var noExec: Bool = false
1517
var hidden: Bool = false
16-
var tmpFs: Bool = false
17-
var caseSensitive: Bool = false
18-
var journaled: Bool = false
1918
var warnOnEject: Bool = false
2019
var folders: [String] = []
2120
var icon: String?
2221

22+
init() {
23+
self.fileSystem = FileSystemManager.availableFileSystems().first?.name ?? "HFS+"
24+
}
25+
26+
init(name: String, size: Int) {
27+
self.name = name
28+
self.size = size
29+
self.fileSystem = FileSystemManager.availableFileSystems().first?.name ?? "HFS+"
30+
}
31+
32+
init?(from dictionary: Dictionary<String, Any>) {
33+
guard let name = dictionary["name"] as? String,
34+
let size = dictionary["size"] as? Int,
35+
let indexed = dictionary["indexed"] as? Bool,
36+
let hidden = dictionary["hidden"] as? Bool
37+
else { return nil }
38+
39+
let warnOnEject = dictionary["warnOnEject"] as? Bool ?? false
40+
let folders = dictionary["folders"] as? [String] ?? []
41+
let icon = dictionary["icon"] as? String
42+
let noExec = dictionary["noExec"] as? Bool ?? false
43+
44+
let fileSystem: String
45+
46+
if let fs = dictionary["fileSystem"] as? String {
47+
fileSystem = fs
48+
} else {
49+
let tmpFs = dictionary["tmpFs"] as? Bool
50+
let caseSensitive = dictionary["caseSensitive"] as? Bool
51+
let journaled = dictionary["journaled"] as? Bool
52+
53+
// We're going to use HSF+ for legacy tmpdisks
54+
if tmpFs ?? false {
55+
fileSystem = "TMPFS"
56+
} else if caseSensitive ?? false && journaled ?? false {
57+
fileSystem = "JHFSX"
58+
} else if caseSensitive ?? false {
59+
fileSystem = "HFSX"
60+
} else if journaled ?? false {
61+
fileSystem = "JHFS+"
62+
} else {
63+
fileSystem = "HFS+"
64+
}
65+
}
66+
67+
self.name = name
68+
self.size = size
69+
self.autoCreate = true
70+
self.fileSystem = fileSystem
71+
self.indexed = indexed
72+
self.hidden = hidden
73+
self.noExec = noExec
74+
self.warnOnEject = warnOnEject
75+
self.folders = folders
76+
self.icon = icon
77+
}
78+
2379
func path() -> String {
24-
if tmpFs {
80+
if FileSystemManager.isTmpFS(fileSystem) {
2581
return "\(TmpDiskManager.rootFolder)/\(name)"
2682
}
2783
return "/Volumes/\(name)"
@@ -37,9 +93,8 @@ struct TmpDiskVolume: Hashable, Codable {
3793
"size": size,
3894
"indexed": indexed,
3995
"hidden": hidden,
40-
"tmpFs": tmpFs,
41-
"caseSensitive": caseSensitive,
42-
"journaled": journaled,
96+
"filesystem": fileSystem,
97+
"noExec": noExec,
4398
"warnOnEject": warnOnEject,
4499
"folders": folders,
45100
"icon": icon ?? "",

TmpDisk.xcodeproj/project.pbxproj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
2264C5E62765667500C45CB8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2264C5E82765667500C45CB8 /* Localizable.strings */; };
3333
2264C5EC27657AAC00C45CB8 /* TmpDiskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2264C5EB27657AAC00C45CB8 /* TmpDiskManager.swift */; };
3434
2264C5EE2765C34000C45CB8 /* NewTmpDiskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2264C5ED2765C34000C45CB8 /* NewTmpDiskViewController.swift */; };
35+
2283B6192D9F6B88007A55F5 /* FileSystemManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2283B6182D9F6B7B007A55F5 /* FileSystemManager.swift */; };
36+
2283B61A2D9F6B88007A55F5 /* FileSystemManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2283B6182D9F6B7B007A55F5 /* FileSystemManager.swift */; };
37+
2283B61C2D9F7ED5007A55F5 /* DropdownTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2283B61B2D9F7ECE007A55F5 /* DropdownTableCellView.swift */; };
3538
228DD7192772F23D00D6CAC3 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228DD7182772F23D00D6CAC3 /* PreferencesViewController.swift */; };
3639
228DD724277426B000D6CAC3 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 228DD723277426B000D6CAC3 /* Sparkle */; };
3740
229EFA552985EAEE001EADB2 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229EFA542985EAEE001EADB2 /* AboutViewController.swift */; };
@@ -140,6 +143,8 @@
140143
2264C5EB27657AAC00C45CB8 /* TmpDiskManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TmpDiskManager.swift; sourceTree = "<group>"; };
141144
2264C5ED2765C34000C45CB8 /* NewTmpDiskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTmpDiskViewController.swift; sourceTree = "<group>"; };
142145
227AF1D52C4D8D5200F3A91B /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
146+
2283B6182D9F6B7B007A55F5 /* FileSystemManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileSystemManager.swift; sourceTree = "<group>"; };
147+
2283B61B2D9F7ECE007A55F5 /* DropdownTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropdownTableCellView.swift; sourceTree = "<group>"; };
143148
228DD7182772F23D00D6CAC3 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
144149
229EFA542985EAEE001EADB2 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
145150
229EFA572985FEB9001EADB2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
@@ -282,6 +287,7 @@
282287
isa = PBXGroup;
283288
children = (
284289
225587372B8FA74100136543 /* Constants.swift */,
290+
2283B6182D9F6B7B007A55F5 /* FileSystemManager.swift */,
285291
225587392B8FA76500136543 /* Protocols.swift */,
286292
225587452B8FB23300136543 /* TmpDiskVolume.swift */,
287293
);
@@ -294,6 +300,7 @@
294300
229EFA542985EAEE001EADB2 /* AboutViewController.swift */,
295301
22A6938A27700B4B0040FDEF /* AutoCreateManagerViewController.swift */,
296302
22A6938C27702BDF0040FDEF /* CheckBoxTableCellView.swift */,
303+
2283B61B2D9F7ECE007A55F5 /* DropdownTableCellView.swift */,
297304
2264C5ED2765C34000C45CB8 /* NewTmpDiskViewController.swift */,
298305
228DD7182772F23D00D6CAC3 /* PreferencesViewController.swift */,
299306
22A6934F276FCDCD0040FDEF /* TmpDiskMenuItem.swift */,
@@ -571,10 +578,12 @@
571578
225587432B8FAAE100136543 /* Constants.swift in Sources */,
572579
225587462B8FB23300136543 /* TmpDiskVolume.swift in Sources */,
573580
225587482B8FB36900136543 /* Util.swift in Sources */,
581+
2283B61C2D9F7ED5007A55F5 /* DropdownTableCellView.swift in Sources */,
574582
225587422B8FAA9A00136543 /* XPCClient.swift in Sources */,
575583
22A69350276FCDCD0040FDEF /* TmpDiskMenuItem.swift in Sources */,
576584
228DD7192772F23D00D6CAC3 /* PreferencesViewController.swift in Sources */,
577585
229EFA552985EAEE001EADB2 /* AboutViewController.swift in Sources */,
586+
2283B61A2D9F6B88007A55F5 /* FileSystemManager.swift in Sources */,
578587
22A6938B27700B4B0040FDEF /* AutoCreateManagerViewController.swift in Sources */,
579588
2264C5EE2765C34000C45CB8 /* NewTmpDiskViewController.swift in Sources */,
580589
2264C5EC27657AAC00C45CB8 /* TmpDiskManager.swift in Sources */,
@@ -609,6 +618,7 @@
609618
files = (
610619
225587402B8FAA5C00136543 /* TmpDiskCreator.swift in Sources */,
611620
225587352B8FA71E00136543 /* XPCServer.swift in Sources */,
621+
2283B6192D9F6B88007A55F5 /* FileSystemManager.swift in Sources */,
612622
2255872A2B8EDB7900136543 /* main.swift in Sources */,
613623
225587382B8FA74100136543 /* Constants.swift in Sources */,
614624
2255873A2B8FA76500136543 /* Protocols.swift in Sources */,
@@ -804,7 +814,7 @@
804814
CODE_SIGN_IDENTITY = "Apple Development";
805815
CODE_SIGN_STYLE = Automatic;
806816
COMBINE_HIDPI_IMAGES = YES;
807-
CURRENT_PROJECT_VERSION = 1015;
817+
CURRENT_PROJECT_VERSION = 1016;
808818
DEAD_CODE_STRIPPING = YES;
809819
DEVELOPMENT_TEAM = AGZ3AP53DM;
810820
ENABLE_HARDENED_RUNTIME = YES;
@@ -838,7 +848,7 @@
838848
CODE_SIGN_IDENTITY = "Apple Development";
839849
CODE_SIGN_STYLE = Automatic;
840850
COMBINE_HIDPI_IMAGES = YES;
841-
CURRENT_PROJECT_VERSION = 1015;
851+
CURRENT_PROJECT_VERSION = 1016;
842852
DEAD_CODE_STRIPPING = YES;
843853
DEVELOPMENT_TEAM = AGZ3AP53DM;
844854
ENABLE_HARDENED_RUNTIME = YES;

TmpDisk.xcodeproj/xcuserdata/tim.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<key>TmpDiskLauncher.xcscheme_^#shared#^_</key>
1818
<dict>
1919
<key>orderHint</key>
20-
<integer>1</integer>
20+
<integer>2</integer>
2121
</dict>
2222
<key>com.imothee.TmpDiskHelper.xcscheme_^#shared#^_</key>
2323
<dict>
2424
<key>orderHint</key>
25-
<integer>2</integer>
25+
<integer>1</integer>
2626
</dict>
2727
</dict>
2828
<key>SuppressBuildableAutocreation</key>

0 commit comments

Comments
 (0)