From 9d541cd18cb25a54209ad2d6f1447a48d5ab0c12 Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Mon, 16 Dec 2024 01:07:56 +0100 Subject: [PATCH] Check for dir existence --- .../performance/NativeBugsnagPerformanceImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java b/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java index 8ee21b33f..0c7e94049 100644 --- a/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java +++ b/packages/platforms/react-native/android/src/main/java/com/bugsnag/android/performance/NativeBugsnagPerformanceImpl.java @@ -143,13 +143,20 @@ void ls(String path, Promise promise) { void mkdir(String path, Promise promise) { Log.w(TAG, "mkdir start " + path); try { - boolean result = new File(path).mkdirs(); + File file = new File(path); + if (file.exists()) { + Log.w(TAG, "mkdir already exists " + path); + promise.reject(new Exception("EEXIST", "Already exists.")); + return; + } + + boolean result = file.mkdirs(); if (result) { Log.w(TAG, "mkdir true " + path); promise.resolve(path); } else { Log.w(TAG, "mkdir false " + path); - promise.reject(new Exception("Failed to create directory")); + promise.reject(new Exception("EPERM", "Failed to create directory ")); } } catch(Exception e) { Log.w(TAG, "mkdir exception " + e.toString());