From b1f467606973e70f2a6571f5579c7ae96a7f03c2 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Tue, 30 Sep 2025 18:38:26 +0000 Subject: [PATCH 1/2] fix: Correctly construct full path when reading directories --- EmpowerPlant/EmpowerPlantViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/EmpowerPlant/EmpowerPlantViewController.swift b/EmpowerPlant/EmpowerPlantViewController.swift index 2abc6f0..3e9c54c 100644 --- a/EmpowerPlant/EmpowerPlantViewController.swift +++ b/EmpowerPlant/EmpowerPlantViewController.swift @@ -115,8 +115,9 @@ class EmpowerPlantViewController: UIViewController { for item in items { var isDirectory: ObjCBool = false - if fm.fileExists(atPath: item, isDirectory: &isDirectory) { - readDirectory(path: item) + let fullPath = (path as NSString).appendingPathComponent(item) + if fm.fileExists(atPath: fullPath, isDirectory: &isDirectory) { + readDirectory(path: fullPath) } else { return } From d8263bf71f9185691a1e4654314b4798114d7ca7 Mon Sep 17 00:00:00 2001 From: kpujjigit <103009467+kpujjigit@users.noreply.github.com> Date: Tue, 30 Sep 2025 13:10:04 -0700 Subject: [PATCH 2/2] add file io tracking disabled directory reading to avoid file io errors --- EmpowerPlant/EmpowerPlantViewController.swift | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/EmpowerPlant/EmpowerPlantViewController.swift b/EmpowerPlant/EmpowerPlantViewController.swift index 3e9c54c..b19295a 100644 --- a/EmpowerPlant/EmpowerPlantViewController.swift +++ b/EmpowerPlant/EmpowerPlantViewController.swift @@ -49,7 +49,7 @@ class EmpowerPlantViewController: UIViewController { getAllProductsFromServer() getAllProductsFromDb() - readCurrentDirectory() + // readCurrentDirectory() // Disabled to avoid scanning outside app sandbox performLongFileOperation() processProducts() checkRelease() @@ -66,11 +66,23 @@ class EmpowerPlantViewController: UIViewController { } func performLongFileOperation() { - let longString = String(repeating: UUID().uuidString, count: 5_000_000) - let data = longString.data(using: .utf8)! - let filePath = FileManager.default.temporaryDirectory.appendingPathComponent("tmp" + UUID().uuidString) - try! data.write(to: filePath) - try! FileManager.default.removeItem(at: filePath) + // Synchronous file I/O on the main thread to demonstrate Sentry's File I/O tracking + // Use a bundled resource to avoid permissions and external paths + if let sourceURL = Bundle.main.url(forResource: "mobydick", withExtension: "txt") { + do { + // Read large file synchronously (main thread) + let data = try Data(contentsOf: sourceURL) + // Write it to Documents and then delete, still on main thread + if let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { + let dest = documents.appendingPathComponent("mobydick_copy_\(UUID().uuidString).txt") + try data.write(to: dest) + try FileManager.default.removeItem(at: dest) + } + } catch { + // Non-fatal: we only need to exercise file I/O for performance demo + print("File I/O demo error: \(error)") + } + } } func processProducts() { @@ -107,7 +119,9 @@ class EmpowerPlantViewController: UIViewController { } } - func readDirectory(path: String) { + func readDirectory(path: String, depth: Int = 0) { + // Limit recursion to prevent deep system traversal + guard depth < 3 else { return } let fm = FileManager.default do { @@ -117,7 +131,9 @@ class EmpowerPlantViewController: UIViewController { var isDirectory: ObjCBool = false let fullPath = (path as NSString).appendingPathComponent(item) if fm.fileExists(atPath: fullPath, isDirectory: &isDirectory) { - readDirectory(path: fullPath) + if isDirectory.boolValue { + readDirectory(path: fullPath, depth: depth + 1) + } } else { return }