Files
Pocket-Poster/Pocket Poster/Controllers/SymHandler.swift
T
2025-06-03 18:36:19 -04:00

56 lines
1.9 KiB
Swift

//
// SymHandler.swift
// Pocket Poster
//
// Created by lemin on 5/31/25.
//
import Foundation
class SymHandler {
// MARK: URL Getter Operations
static func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
private static func getSymlinkURL() -> URL {
let lcPath = ProcessInfo.processInfo.environment["LC_HOME_PATH"]
var docsDir = getDocumentsDirectory()
if let lcPath = lcPath {
docsDir = URL(fileURLWithPath: "\(lcPath)/Documents")
}
return docsDir.appendingPathComponent(".Trash", conformingTo: .symbolicLink)
}
// MARK: Symlink Creation
static func createSymlink(to path: String) throws -> URL {
// returns the url of the symlink
let symURL = getSymlinkURL()
cleanup()
// create the symlink to the hashed app folder
try FileManager.default.createSymbolicLink(at: symURL, withDestinationURL: URL(fileURLWithPath: path, isDirectory: true))
return symURL
}
static func createAppSymlink(for appHash: String) throws -> URL {
return try createSymlink(to: "/var/mobile/Containers/Data/Application/\(appHash)")
}
static func createDescriptorsSymlink(appHash: String, ext: String) throws -> URL {
// create a symlink directly to the descriptors
print("linking to \(appHash)/Library/Application Support/PRBPosterExtensionDataStore/61/Extensions/\(ext)/descriptors")
return try createAppSymlink(for: "\(appHash)/Library/Application Support/PRBPosterExtensionDataStore/61/Extensions/\(ext)/descriptors")
}
static func cleanup() {
// remove the symlink if it exists
let symURL = getSymlinkURL()
// remove existing symlink
try? FileManager.default.removeItem(at: symURL)
}
}